Laravel model binding not working for delete
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) {
$task->delete();
return redirect('/');
});
And below is my form for delete:
<form action="{{url('/task', [$task->id])}}" method="post">
{{csrf_field()}}
{{method_field('DELETE')}}
<button class="btn btn-danger">Delete</button>
</form>
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',
]);
if($validator->fails())
{
return redirect('/')->withInput()->withErrors($validator);
}
$task = new Task();
$task->title = $request->title;
$task->active = 1;
$task->save();
return redirect('/');
});
Thank you
Answer
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
Related Questions
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS - Conditionally Load a Different Page
- → Make a Laravel collection into angular array (octobercms)
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?
- → Validating fileupload(image Dimensions) in Backend Octobercms
- → OctoberCMS Fileupload completely destroys my backend
- → How do I call the value from another backed page form and use it on a component in OctoberCms