jeudi 1 septembre 2016

What is the best practice to work with forms in Laravel?

I'm writing my first Laravel app and i'm confused a little about how laravel works with forms.

In the head of my app - image generation. I need help with app logic and maybe some links to docs that will help me understand how to write good code.
I call it scene manager. Manager have 3 main functions - create, edit, delete scene. I have ugly form to create scene. In this form i have to collect info 3 diff layers of photo (like mask, effects, etc) - width, height, control points where top image will be placed. Kinda tricky a little. Here is an image: form

I created a viewer for this form, route takes me there .. and if i've got right - i have to submit this form to the SceneController. Where i will receive data, save image to the server and write data to DB. Than i must call outside php script to do some magic and return me an image - that i have to show on result page.

I discovered that i can use FORM method:
// with arguments:

'url' => 'generate', 'method'=>'POST', 'files'=>true

but what is the best practice to collect, send and receive data? Object / array or what?

Will be glad to see your ideas, sources, links. I'm really confused about that. Thanks!



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2bTzJOw
via IFTTT

Laravel return the page on any address except from routes

I have a list of routes for my Laravel application. Now, I want to return the same page as is returned on / for all routes that are not listed. I.e.

/hello/world <-> binded to "Hello world" page
/blah/blah <-> binded to "Blah Blah" p

Now, no matter what user requests (GET) and how many slashes in the request are (/asdfda/sadfasdf/asdfasdf, eafsadfsda, asdfadsfasd/adsfsdaf), I want to return the same page. I do not want it to be 404 though, as I want to keep that a legal route.


I tried

Route::get('{all?}', [
    'as' => 'spa.index',
    'uses' => 'SPAController@index',
]);

But that works only if there are no slashes.


Do someone knows how to do that?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2bGumo8
via IFTTT

How to update image using controller in laravel?

I want to update user image but it's not getting updated. I have used following controller for updating the image.. Can you suggest what's the mistake in controller function?

View part :

<div class="form-group">
            <label>Image Upload</label>
            <input type="file" name="image"  id="image"><img src="" width="200px"/></br>
 </div> 

Controller function :

public function update(Request $request, $id)
{
    $data=Course::findOrFail($id);  

    if ($request->hasFile('image'))
        {
            $file = $request->file('image');
            $timestamp = str_replace([' ', ':'], '-', Carbon::now()->toDateTimeString()); 
            $name = $timestamp. '-' .$file->getClientOriginalName();
            $data->image = $name;
            $file->move(public_path().'/images/', $name);              
        }   
          $data->update($request->all());              
      return redirect('course');
}



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2bLrVxX
via IFTTT

POST http://localhost:8080/myapp/public/login 401 (Unauthorized) in calling Laravel API

Hello I have a laravel API to call for login. But seems the angular js won't pass the data from input. I'm just new to Angular.

Here's my Login controller:

public function login(Request $request) { $email = $request->input('email'); $password = $request->input('password'); $user = User::where('email', '=', $email)->first(); if (!$user) { //return an error if user is not found in the database return response()->json(['error' => 'employee_not_authorized'], 401); } else { try{ // verify the credentials and create a token for the user if (!$token = JWTAuth::fromUser($user)) { return response()->json(['error' => 'invalid_credentials'], 401); } } catch (JWTException $e) { return response()->json(['error' => 'could_not_create_token'], 500); } // if no errors are encountered we can return a JWT return response()->json(compact('token')); } }

And here's my angularjs controller for login that consumes laravel api but it is not working, it kept me giving error authorize 401 though testing in postman, laravel api works.

Signin: function (username, password) { //return $http.get("http://localhost:8080/bcpp/webservice/api.php?action=login&employee_id=" + username + "&pass=" + password) //.then(function (response) { // return (response.data); //});
return $http({ url: "../login", method: 'POST', data: { email: username, password: password }, headers: { 'Content-Type' : 'application/x-www-form-urlencoded'} }); },

Disclaimer: some code intended not to be completed.Please help. Thank you.



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2bGsgEU
via IFTTT

How to update file in laravel 5 without losing the previous file

I have a form with multiple input in it, here is the code :

@if (isset($jurnal))
    {!! Form::hidden('id', $jurnal->id) !!}
@endif

@if ($errors->any())
    <div class="form-group ">
@else
    <div class="form-group">
@endif
    {!! Form::label('title', 'Title :', ['class' => 'control-label']) !!}
    {!! Form::text('title', null, ['class' => 'form-control']) !!}
    @if ($errors->has('title'))
        <span class="help-block"></span>
    @endif
</div>

@if ($errors->any())
    <div class="form-group ">
@else
    <div class="form-group">
@endif
    {!! Form::label('author', 'Author :', ['class' => 'control-label']) !!}
    {!! Form::text('author', null, ['class' => 'form-control']) !!}
    @if ($errors->has('author'))
        <span class="help-block"></span>
    @endif
</div>

@if ($errors->any())
    <div class="form-group ">
@else
    <div class="form-group">
@endif
    {!! Form::label('file', 'File Jurnal (PDF) :') !!}
    {!! Form::file('file') !!}
    @if ($errors->has('file'))
        <span class="help-block"></span>
    @endif
</div>

<div class="form-group">
    {!! Form::submit($submitButtonText, ['class' => 'btn btn-primary form-control']) !!}
</div>

And here is the controller :

private function uploadPDF(JurnalRequest $request)
    {
        $file = $request->file('file');
        $ext  = $file->getClientOriginalExtension();

        if ($request->file('file')->isValid()) {
            $pdf_name   = date('YmdHis'). ".$ext";
            $upload_path = 'pdfupload';
            $request->file('file')->move($upload_path, $pdf_name);

            // Filename untuk database --> 20160220214738.pdf
            return $pdf_name;
        }
        return false;
    }

    public function store(JurnalRequest $request)
    {
        $input = $request->all();

        //Input PDF
        if ($request->hasFile('file')) {
            $input['file'] = $this->uploadPDF($request);
        }

        //Insert data jurnal
        $jurnal = Jurnal::create($input);

        return redirect('jurnal');
    }

These data are editable including the file, what I wanted to know is that how is the update function would look like ? For example, the user wanted to update the title or the author data but not the file, how to do it without losing the previous file ? I am new to Laravel 5 and I'm stuck here, please help, thank you.



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2cfOyfC
via IFTTT

Laravel configuration error: The cipher and / or key length are invalid

I am using laravel 5 i have tried possible solution on similar question on stack but that didn't helped me . Below are my updated files that i edited

My .env file is updated with appkey see here

generated appkey with php artisan command key generate and put that in . env

APP_ENV=local
APP_DEBUG=true
APP_KEY=[9vkErFVjzUX3ozuOcD7T7KTHNKP2FBNB]

DB_HOST=localhost
DB_DATABASE=blogdb
DB_USERNAME=rootDB_PASSWORD=

CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync

MAIL_DRIVER=smtp
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null

Also Updated app.php file cipher and appkey manually

  'key' => env('APP_KEY', '[9vkErFVjzUX3ozuOcD7T7KTHNKP2FBNB]'),

  'cipher' => 'AES-256-CBC',

Don't know why it is generating 34 bit app key using php artisan command



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2bGf2YL
via IFTTT

intall Laravel after PC Format

New to the Laravel I'm going to format My PC and now working with Laravel 5.2 after I install new OS (windows 10) I'm going to install my Laravel project again this way 1.install WAMP 2.install Dependency Manager for PHP 3.copy My laravel file and DB is this correct way?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2bEGWat
via IFTTT