Thursday, March 9, 2017

FatalErrorException in routes.php line 113: Call to a member function delete() on null in Laravel 5.2

I am trying to delete a file through routes.php but it is generating the following error:

FatalErrorException in routes.php line 113: Call to a member function delete() on null

This is the view where the function is placed in the delete button.

<div class="col-md-12 col-xs-12">
        <div class="row">
            @foreach($properties->files as $index=>$file)

                  <div class="col-sm-6 col-md-2">
                    <div class="thumbnail">
                      <img src="" alt="" width="300" height="200">
                      <div class="caption">
                        <div class="caption" align="center">
                            <form action="" method="POST" enctype="multipart/form-data">
                                
                                
                                <button onclick="return confirm('Está seguro eliminar esta imagen?')" class="button btn btn-danger btn-xs" data-toggle="tooltip" data-placement="top" title="Eliminar imagen"><i class="material-icons delete-white">delete</i></button>
                            </form>
                        </div>
                      </div>
                    </div>
                  </div>           

            @endforeach
        </div>
    </div>

And this is the path I'm using to delete the file in the directory and database.

// Delete files
    Route::delete('/file/{id}', function ($id) {
        //File::findOrFail($id)->delete();
        $file = File::find(Input::get('id')->delete());

        $filename= Input::get('upload');
        $path = 'uploads/products/' . $file->filename;

        //return redirect('/');
        return redirect()->back()->with('success', 'Imagen eliminada satisfactoriamente!!!');

    });



via Edward Palen

Advertisement