DoeJohn's avatar

Laravel 5.2 & Dropzone.js - Remove (Delete) uploaded images

Hi,

My Dropzone uploading is working fine, but I would like to have the remove links for each uploaded image. The problem is that my remove links are not even shown, and also I don't know how to do it. I was reading http://www.dropzonejs.com/ and some other tutorials, but it is still unclear.

Here is my HTML / JS:

            {!! Form::open(['url' => route('dropzone.upload'), 'class' => 'dropzone', 'files'=>true, 'id'=>'my-dropzone']) !!}

                <div class="dz-message">
                </div>

                <div class="fallback">
                    <input name="file" type="file" multiple />
                </div>

                <h4 class="text-center" style="color:#428bca;">Drop images in this area  <span class="glyphicon glyphicon-hand-down"></span></h4>
                <div class="text-center">or just click to browse</div>

            {!! Form::close() !!}
    <script type="text/javascript">

        Dropzone.autoDiscover = false;

        var myDropzone = new Dropzone("#my-dropzone", {
            url: "{{ route('dropzone.upload') }}",
            headers: {
                'X-CSRF-TOKEN': '{!! csrf_token() !!}'
            }
        });

        Dropzone.options.myDropzone = {
            addRemoveLinks: true,
            dictRemoveFile: 'Remove',
            // -------------->    AND NOW WHAT ???????? 
        };

    </script>

My routes.php:

    Route::post('dropzone', ['as' => 'dropzone.upload', 'uses' => 'AdminPhotoController@dropzoneUpload']);
    Route::post('dropzone/delete', ['as' => 'dropzone.delete', 'uses' => 'AdminPhotoController@dropzoneDelete']);

Controller method for uploading:

    public function dropzoneUpload(Request $request)
    {
        if($request->ajax()) {
            if ($request->hasFile('file') && $request->file('file')->isValid()) {
                $image_file = $request->file('file');
                $image_name = time() . '_' . $image_file->getClientOriginalName();
                $destinationPath = 'images/photos';

                if ($image_file->move($destinationPath, $image_name)) {
                    $photo = new Photo(['file_name' => $image_name, 'title' => 'No title', 'description' => 'No description']);
                    \Auth::user()->photos()->save($photo);

                    return \Response::json('success', 200);
                } else {
                    return \Response::json('error', 400);
                }
            }
        }
    }


    public function dropzoneDelete(Request $request)
    {
        if($request->ajax()) {
        // This should be a method to delete.... WHAT SHOULD I PUT HERE?
        }
    }
0 likes
0 replies

Please or to participate in this conversation.