Laravel形式不会修补,只有POST-嵌套的RESTfull控制器,MethodNotAllowedHttpException [英] Laravel form won't PATCH, only POST - nested RESTfull Controllers, MethodNotAllowedHttpException
问题描述
我正试图允许用户编辑他们的播放列表.但是,每当我尝试执行PATCH请求时,都会出现 MethodNotAllowedHttpException 错误. (正在等待POST)
I am trying to allow users to edit their playlist. However, whenever I try to execute the PATCH request, I get the MethodNotAllowedHttpException error. (it is expecting a POST)
我已经设置了RESTful资源控制器:
I have set up RESTful Resource Controllers:
Routes.php:
Routes.php:
Route::resource('users', 'UsersController');
Route::resource('users.playlists', 'PlaylistsController');
这应该使我可以访问:(通过 php artisan路线显示)
This should give me access to: (as displayed through php artisan routes)
URI | Name | Action
PATCH users/{users}/playlists/{playlists} | users.playlists.update | PlaylistsController@update
但是,当我尝试执行以下表单时,出现 MethodNotAllowedHttpException 错误:
However, when I try to execute the following form, I get the MethodNotAllowedHttpException error:
/users/testuser/playlists/1/edit
/users/testuser/playlists/1/edit
{{ Form::open(['route' => ['users.playlists.update', $playlist->id], 'method' => 'PATCH' ]) }}
{{ Form::text('title', $playlist->title) }}
{{ Form::close() }}
如果我删除了'method'=> 'PATCH'
,我不会收到错误,但它会执行我的public function store()
而不是我的public function update()
If I remove 'method'=> 'PATCH'
I don't get an error, but it executes my public function store()
and not my public function update()
推荐答案
在Laravel 5及更高版本中:
In Laravel 5 and up:
<form method="POST" action="patchlink">
@method('patch')
. . .
</form>
这篇关于Laravel形式不会修补,只有POST-嵌套的RESTfull控制器,MethodNotAllowedHttpException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!