Laravel 资源路由 - 更新抛出“方法不允许”错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33169647/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 12:30:53  来源:igfitidea点击:

Laravel resource routing - update throws "method not allowed" error

phplaravellaravel-4

提问by jovan

I have the following resource route:

我有以下资源路线:

Route::resource('pools', 'PoolsController');

I also have an edit form which should post to the controller's "update" method, set up like this:

我还有一个编辑表单,它应该发布到控制器的“更新”方法,设置如下:

{{ Form::open(array('route' => ['pools.update', $pool['id']])) }}

When I submit the form, it opens www.domain.com/pools/6 (6 being $pool['id']above). However, instead of running the code in the update()method, it throws an error:

当我提交表单时,它会打开 www.domain.com/pools/6($pool['id']上面是6 )。但是,它没有运行update()方法中的代码,而是抛出错误:

Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException

Now, I've found Laravel's error reporting very unhelpful so far, and this is no exception. The error description is vague at best and does nothing to help me troubleshoot the issue.

现在,到目前为止,我发现 Laravel 的错误报告非常无用,这也不例外。错误描述充其量是含糊的,并没有帮助我解决问题。

I was under the impression that the update method should receive post data automatically when using resourceful routing. It has also worked in some examples before, using the same syntax.

我的印象是更新方法在使用资源丰富的路由时应该自动接收发布数据。它在之前的一些示例中也使用过相同的语法。

So, can anyone tell me what might be going on here?

那么,谁能告诉我这里可能会发生什么?

采纳答案by Andrei C

to run the code in the update method, you must spoof a PUT request. look here: Form Method Spoofing

要在 update 方法中运行代码,您必须欺骗 PUT 请求。看这里:表单方法欺骗