Msoft's avatar
Level 1

how to form submission work with route link in laravel 5.6

I am following a tutorials with laravel 5.6 and dropzone box for uploading images. this is my form,

<form method="post" action="{{ url('/images-save') }}"
                  enctype="multipart/form-data" class="dropzone" id="my-dropzone">
                {{ csrf_field() }}
                <div class="dz-message">
                    <div class="col-xs-8">
                        <div class="message">
                            <p>Drop files here or Click to Upload</p>
                        </div>
                    </div>
                </div>
                <div class="fallback">
                    <input type="file" name="file" multiple>
                </div>
            </form>

//submission link
<a class="navbar-brand" href="{{ url('/') }}">Upload</a>

and My routes is like this,

Route::get('/', 'UploadImagesController@create');
Route::post('/images-save', 'UploadImagesController@store');

Controller is,

 public function store(Request $request)
    {
        
        $photos = $request->file('file');
 
        if (!is_array($photos)) {
            $photos = [$photos];
        }
 
        if (!is_dir($this->photos_path)) {
            mkdir($this->photos_path, 0777);
        }
 
        for ($i = 0; $i < count($photos); $i++) {
            $photo = $photos[$i];
            $name = sha1(date('YmdHis') . str_random(30));
            $save_name = $name . '.' . $photo->getClientOriginalExtension();
            $resize_name = $name . str_random(2) . '.' . $photo->getClientOriginalExtension();
 
            Image::make($photo)
                ->resize(250, null, function ($constraints) {
                    $constraints->aspectRatio();
                })
                ->save($this->photos_path . '/' . $resize_name);
 
            $photo->move($this->photos_path, $save_name);
 
            $upload = new Upload();
            $upload->filename = $save_name;
            $upload->resized_name = $resize_name;
            $upload->original_name = basename($photo->getClientOriginalName());
            $upload->save();
        }
        return Response::json([
            'message' => 'Image saved Successfully'
        ], 200);
    }

any way above codes working well but I can't understand how this submission link work with routes, can you anybody describe how works this link with above routes.

0 likes
1 reply
jlrdw's avatar

If you are asking how routing works in the background Google front controller and read a few articles on that.

Please or to participate in this conversation.