【Error】 MethodNotAllowedHttpException

Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException
No message
这里写图片描述
上面是报的错,下面是想获取的数据。
页面代码:php

<form role="form" method="post" action="{route{'articles'}}">

路由代码:css

Route::post('/articles','ArticlesController@store');

控制器:laravel

public function store(Request $request){
   dd($request->all());//想获取request数据
}

解决办法:
//把action改成和路由同样的路径web

<form role="form" method="post" action="/articles">

//在表单里任意位置加上这句express

<input type="hidden" name="_token" value="{{csrf_token()}}"/>

参考laravel文档:svg

  • 【原理】CSRF防御

在 web 路由文件中全部请求方式为PUT、POST或DELETE的HTML表单都会包含一个CSRF令牌字段,不然,请求会被拒绝。
成功获取:
这里写图片描述post