I'm building a really simple CRUD in laravel just to learn something about this framework. It works all like a charm but I can't make the update function of a controller work properly.
Here my situation:
1) I build a resource controller using artisan command.
2) I build a form view using blade and I Open the form with this code:
<!-- Form -->
@if($mode=="edit")
{{ Form::model($task, array('route'=>array('task.update',$task->id),'files'=>true)) }}
@else
{{ Form::open(array('route'=>'task.store','files'=>true)) }}
@endif
It works great and every field are filled with the right data. The generate url of the form's action is:
http://localhost/mysite/task/2
The problem is that when I submit this form I get this error:
Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException
Someone can understand why? Can I help you with more information?
You need 'method' => 'put'.
{{ Form::model($task, array('route' => array('task.update', $task->id), 'files' => true, 'method' => 'PUT')) }}
As you can see here.
http://laravel.com/docs/controllers#resource-controllers
Verb: PUT/PATCH
Path: /resource/{id}
action: update
route: resource.update
EDIT: To trigger the update()-action you must send a PUT or PATCH-request to the route resource.update
, in your case task.update
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With