【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