RouteCollection.php 第 219 行中的 MethodNotAllowedHttpException

MethodNotAllowedHttpException in RouteCollection.php line 219(RouteCollection.php 第 219 行中的 MethodNotAllowedHttpException)
本文介绍了RouteCollection.php 第 219 行中的 MethodNotAllowedHttpException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

当我存储帖子时出现此错误

When I storing a post I get this error

MethodNotAllowedHttpException in RouteCollection.php line 219:

什么会导致这个问题??

What can cause this problem ??

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', 'AuthAuthController@getLogin');
Route::post('auth/login', 'AuthAuthController@postLogin');
Route::get('auth/logout', 'AuthAuthController@getLogout');

// Registration routes...
Route::get('auth/register', 'AuthAuthController@getRegister');
Route::post('auth/register', 'AuthAuthController@postRegister');

我正在使用 Laravel 5.1,但我一天都想不通..

I'm using Laravel 5.1 and I can't figure this out for a day..

推荐答案

由于您将帖子更新的方法设置为 patch,请确保您打开您的表单以使用该方法:

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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

In PHP how can you clear a WSDL cache?(在 PHP 中如何清除 WSDL 缓存?)
failed to open stream: HTTP wrapper does not support writeable connections(无法打开流:HTTP 包装器不支持可写连接)
Stop caching for PHP 5.5.3 in MAMP(在 MAMP 中停止缓存 PHP 5.5.3)
Caching HTTP responses when they are dynamically created by PHP(缓存由 PHP 动态创建的 HTTP 响应)
Memcached vs APC which one should I choose?(Memcached 与 APC 我应该选择哪一个?)
What is causing quot;Unable to allocate memory for poolquot; in PHP?(是什么导致“无法为池分配内存?在 PHP 中?)