RouteCollection.php第219行中的MethodNotAllowedHttpException [英] MethodNotAllowedHttpException in RouteCollection.php line 219
问题描述
存储帖子时出现此错误
MethodNotAllowedHttpException in RouteCollection.php line 219:
什么会导致此问题?
Routes.php:
Routes.php:
Route::get('home', 'PostsController@index');
Route::get('/', 'PostsController@index');
Route::get('index', 'PostsController@index');
Route::get('posts', 'PostsController@index');
Route::get('post/{slug}/{id}', 'PostsController@show');
Route::get('posts/sukurti-nauja-straipsni', 'PostsController@create');
Route::patch('posts/store-new-post', 'PostsController@store');
Route::get('post/{slug}/{id}/edit', 'PostsController@edit');
Route::patch('posts/{slug}', 'PostsController@update');
Route::get('tags/{tags}', 'TagsController@show');
Route::get('categories/{categories}', 'CategoriesController@show');
// Authentication routes...
Route::get('auth/login', 'Auth\AuthController@getLogin');
Route::post('auth/login', 'Auth\AuthController@postLogin');
Route::get('auth/logout', 'Auth\AuthController@getLogout');
// Registration routes...
Route::get('auth/register', 'Auth\AuthController@getRegister');
Route::post('auth/register', 'Auth\AuthController@postRegister');
我正在使用Laravel 5.1,我一天都无法解决..
I'm using Laravel 5.1 and I can't figure this out for a day..
推荐答案
Since you're setting the method on the post's update to be patch
, be sure you open your form to use that method:
{!! Form::open(['method' => 'patch']) !!}
如果您不使用Form
类,则还可以确保有一个_method :
If you're not using the Form
class, you can also just ensure there's a hidden element called _method
underneath the form:
<input name="_method" type="hidden" value="PATCH">
同样,如果要通过AJAX发送此数据,只需在通过POST发送请求之前,将_method
密钥添加到设置为'PATCH'
的有效负载中即可.某些浏览器( IE 7/8 )不支持通过XMLHttpRequest的PATCH HTTP
Similarly, if you're sending this data via AJAX, just add a _method
key to the payload set to 'PATCH'
before sending the request via POST. Some browsers (IE 7/8) do not support PATCH HTTP through XMLHttpRequest
您的另一种选择是改为更改路由以接受POST数据:
Your other option is to change your route to accept POST data instead:
Route::post('posts/store-new-post', 'PostsController@store');
Route::post('posts/{slug}', 'PostsController@update');
这篇关于RouteCollection.php第219行中的MethodNotAllowedHttpException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!