MethodNotAllowedHttpException in RouteCollection.php line 219(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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:RouteCollection.php 第 219 行中的 MethodNotAllowedHttpExc
基础教程推荐
- 如何在 Symfony 和 Doctrine 中实现多对多和一对多? 2022-01-01
- 如何在 XAMPP 上启用 mysqli? 2021-01-01
- phpmyadmin 错误“#1062 - 密钥 1 的重复条目‘1’" 2022-01-01
- PHP 守护进程/worker 环境 2022-01-01
- 使用 PDO 转义列名 2021-01-01
- HTTP 与 FTP 上传 2021-01-01
- 找不到类“AppHttpControllersDB",我也无法使用新模型 2022-01-01
- Doctrine 2 - 在多对多关系中记录更改 2022-01-01
- 在 CakePHP 2.0 中使用 Html Helper 时未定义的变量 2021-01-01
- 在 yii2 中迁移时出现异常“找不到驱动程序" 2022-01-01