csrf_token提交时一直报错,查看源代码有隐藏的token值
源代码
<form method="post" action="/data">
<input type="hidden" name="_token" value="XsRtQ4X8xMqlWRDpf1VgrStFTaxBAArdjfx0NyRd">
<input type="text" name="name">
<input type="submit" value="提交">
</form>
错误提示
TokenMismatchException in VerifyCsrfToken.php line 67:
in VerifyCsrfToken.php line 67
at VerifyCsrfToken->handle(object(Request), object(Closure))
at call_user_func_array(array(object(VerifyCsrfToken), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in ShareErrorsFromSession.php line 49
at ShareErrorsFromSession->handle(object(Request), object(Closure))
at call_user_func_array(array(object(ShareErrorsFromSession), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
路由代码
Route::group(['middleware'=>'web'], function (){
Route::get('/form', function(){
return view('form');
});
Route::post('/data', function (){
return dd($_POST);
});
});
前端代码
<div class="container">
<form method="post" action="/data">
csrf_field()
<input type="text" name="name">
<input type="submit" value="提交">
</form>
</div>