问题
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:
回答1:
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.
回答2:
use put method like this within form,for more https://laravel.com/docs/5.2/routing#form-method-spoofing
{{ method_field('PUT') }}
回答3:
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,PATCHorDELETEactions. So, when definingPUT,PATCHorDELETEroutes that are called from an HTML form, you will need to add a hidden_methodfield to the form.if you are making the request from a HTML form, and you have the
VerifyCsrfTokenmiddleware enable, than you will need to add a hidden_tokenfield to the form with{{ csrf_token() }}as value.
来源:https://stackoverflow.com/questions/35431617/laravel-5-methodnotallowedhttpexception-put