I am trying to update a user, but when I hit the submit button, Laravel throws the below error:
"RouteCollection->methodNotAllowed(array('GET', 'HEAD', 'POST')) in RouteCollection.php line 206".
I think that the PUT
method is not allowed, but I do not understand the reason. The request never reaches UserController@update
.
I have configured a resource route like this:
Route::resource('backend/users', 'Backend\UsersController');
The output of php artisan route:list
is:
I solved the problem like this: it must be the form's post action error;
<form method="POST" action="10.241.229.1/backend/users/{{$user->id}}"; accept-charset="UTF-8">
add the id you want update to the action.
use put method like this within form,for more https://laravel.com/docs/5.2/routing#form-method-spoofing
{{ method_field('PUT') }}
Coming a bit late on this question.
In my experience this kind of error comes for two reasons:
as Laravel docs say, HTML forms do not support PUT
, PATCH
or DELETE
actions. So, when defining PUT
, PATCH
or DELETE
routes that are called from an HTML form, you will need to add a hidden _method
field to the form.
if you are making the request from a HTML form, and you have the VerifyCsrfToken
middleware enable, than you will need to add a hidden _token
field to the form with {{ csrf_token() }}
as value.