[英]Laravel 5.1.26 : MethodNotAllowedHttpException in RouteCollection.php line 219
I will get MethodNotAllowedHttpException
when submitting a form in laravel 在Laravel中提交表单时,我将获得MethodNotAllowedHttpException
HTML file HTML文件
<form action="{{ action('HomeController@store') }}" method="post">
<input name="_method" type="hidden" value="PATCH">
<input name="_token" type="hidden" value="{{ csrf_token() }}"/>
<input type="submit" name="Submit" value="submit">
</form>
Im my routes.php 我是我的routes.php
Route::post('formaction','HomeController@store')
Controller.php Controller.php这样
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
class HomeController extends Controller
{
public function store(){
echo 'form submitted';
}
}
Why i will get MethodNotAllowedHttpException in my form action page? 为什么我会在表单操作页面中得到MethodNotAllowedHttpException? I've refereed some questions related to this,but nothing help me 我已经参考了一些与此相关的问题,但没有任何帮助
Even if the form is using the POST method, you are sending the extra param _method
which will let the framework know that you want to use that method instead. 即使表单使用POST方法,您也会发送额外的参数_method
,它将使框架知道您想使用该方法。 If you send that extra param then you should set the route accordingly: 如果发送该额外参数,则应相应地设置路线:
Route::patch('formaction','HomeController@store');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.