Laravel model binding not working for delete

- 1 answer


I am asking a very basic question, and i searched for more than two hours, but still i was not able to fix it. I am new to laravel, and trying to read their example for Tasks. But some how the delete is not working. Below is my code for route:

Route::delete('/task/{task}', function(\AltafBlog\Task $task) {
     return redirect('/');

And below is my form for delete:

<form action="{{url('/task', [$task->id])}}" method="post">
   <button class="btn btn-danger">Delete</button>

Now when i click on delete button, it does not delete the item in the table. Also, i dont get any error message. Adding new items and listing them are working fine. I am not sure what i am doing wrong. Can anybody suggest what is going on there?

Update: After updating to laravel 5.2, the model binding is working, but the Validator is not working in post route. the post route is as below:

Route::post('/task', function(Request $request) {
$validator = Validator::make($request->all(), [
    'title'  =>  'required|max:255',
    return redirect('/')->withInput()->withErrors($validator);
    $task = new Task();
    $task->title = $request->title;
    $task->active = 1;
    return redirect('/');

Thank you




The problem in Laravel version. Laravel 5.1.24 doesn't have implicit bindings.

So, if you want to use it you should use (or upgrade) Laravel 5.2.* Upgrading To 5.2.0 From 5.1