Laravel 5 MethodNotAllowedHttpException PUT
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35431617/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel 5 MethodNotAllowedHttpException PUT
提问by simon volk
I am trying to update a user, but when I hit the submit button, Laravel throws the below error:
我正在尝试更新用户,但是当我点击提交按钮时,Laravel 抛出以下错误:
"RouteCollection->methodNotAllowed(array('GET', 'HEAD', 'POST')) in RouteCollection.php line 206".
“RouteCollection->methodNotAllowed(array('GET', 'HEAD', 'POST')) 在 RouteCollection.php 第 206 行”。
I think that the PUT
method is not allowed, but I do not understand the reason. The request never reaches UserController@update
.
我认为该PUT
方法是不允许的,但我不明白原因。请求永远不会到达UserController@update
。
I have configured a resource route like this:
我已经配置了这样的资源路由:
Route::resource('backend/users', 'Backend\UsersController');
The output of php artisan route:list
is:
php artisan 的输出route:list
是:
回答by allen
I solved the problem like this: it must be the form's post action error;
我是这样解决的:一定是表单的post action错误;
<form method="POST" action="10.241.229.1/backend/users/{{$user->id}}"; accept-charset="UTF-8">
<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.
将您要更新的 ID 添加到操作中。
回答by Imtiaz Pabel
use put method like this within form,for more https://laravel.com/docs/5.2/routing#form-method-spoofing
在表单中使用这样的 put 方法,了解更多https://laravel.com/docs/5.2/routing#form-method-spoofing
{{ method_field('PUT') }}
回答by Giorgio Ghiatis
Coming a bit late on this question.
这个问题来得有点晚。
In my experience this kind of error comes for two reasons:
根据我的经验,出现这种错误有两个原因:
as Laravel docssay, HTML forms do not support
PUT
,PATCH
orDELETE
actions. So, when definingPUT
,PATCH
orDELETE
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.
正如Laravel 文档所说,HTML 表单不支持
PUT
,PATCH
或DELETE
动作。因此,当定义PUT
,PATCH
或DELETE
从 HTML 表单调用的路由时,您需要向表单添加一个隐藏_method
字段。如果您从 HTML 表单发出请求,并且
VerifyCsrfToken
启用了中间件,则您需要_token
使用{{ csrf_token() }}
as 值向表单添加一个隐藏字段。