VerifyCsrfToken.php中的Laravel令牌不匹配异常

VerifyCsrfToken.php中的Laravel令牌不匹配异常,php,laravel,laravel-5,Php,Laravel,Laravel 5,我使用的是Laravel 5,在我的表单上单击提交时出现错误 HTML 试验 这是一个测试页面 路线 Route::post('/plant/sayLove2','ApartmentController@sayLove2'); 控制器 namespace-App\Http\Controllers; 使用\Http\Request; 类ApartmentController扩展控制器 { 公共职能部门2(请求$Request) { $id=$request->input('id'); ech

我使用的是Laravel 5,在我的表单上单击提交时出现错误

HTML


试验
这是一个测试页面
路线

Route::post('/plant/sayLove2','ApartmentController@sayLove2');
控制器

namespace-App\Http\Controllers;
使用\Http\Request;
类ApartmentController扩展控制器
{
公共职能部门2(请求$Request)
{
$id=$request->input('id');
echo$id;
出口
$team=$request->input('team');
$BestPlayerTheWorld=$request->input('BSetPlayerTheWorld');
返回视图('sayLove',['id'=>id$team=>team]);
}
}
错误

VerifyCsrfToken.php第67行中的令牌不匹配异常: 在VerifyCsrfToken.php第67行中 在VerifyCsrfToken->handle(对象(请求)、对象(关闭)) 在Pipeline.php第136行中调用_user_func_数组(数组(对象(VerifyCsrfToken),'handle')、数组(对象(请求)、对象(闭包)) 在管道->照明\管道{closure}(对象(请求)) 在Pipeline.php第32行中调用_user_func(对象(闭包)、对象(请求)) 在ShareErrorsFromSession.php第49行的管道->照明\路由{closure}(对象(请求)) 在ShareErrorsFromSession->handle(对象(请求)、对象(关闭)) 在Pipeline.php中调用_user_func_数组(数组(对象(ShareErrorsFromSession),'handle')、数组(对象(请求)、对象(闭包)) 第136行 在管道->照明\管道{closure}(对象(请求)) 在Pipeline.php第32行中调用_user_func(对象(闭包)、对象(请求)) 在StartSession.php第62行的Pipeline->illumb\Routing{closure}(对象(请求))中 开始时会话->句柄(对象(请求)、对象(关闭)) 在Pipeline.php第136行中调用_user_func_数组(数组(object(StartSession),'handle')、数组(object(Request),object(Closure)) 在管道->照明\管道{closure}(对象(请求)) 在Pipeline.php第32行中调用_user_func(对象(闭包)、对象(请求)) 在AddQueuedCookiesToResponse.php第37行的管道->照明\路由{closure}(对象(请求)) 在AddQueuedCookiesToResponse->handle(对象(请求)、对象(关闭)) 在Pipeline.php中调用\用户\函数\数组(数组(对象(AddQueuedCookiestResponse),'handle')、数组(对象(请求)、对象(闭包)) 第136行 在管道->照明\管道{closure}(对象(请求)) 在Pipeline.php第32行中调用_user_func(对象(闭包)、对象(请求)) 在EncryptCookies.php第59行的Pipeline->illumb\Routing{closure}(对象(请求))中 在加密cookies->handle(对象(请求)、对象(关闭)) 在Pipeline.php第136行中调用_user_func_数组(数组(对象(EncryptCookies),'handle')、数组(对象(请求)、对象(闭包)) 在管道->照明\管道{closure}(对象(请求)) 在Pipeline.php第32行中调用_user_func(对象(闭包)、对象(请求)) 在管道->照明\路由{closure}(对象(请求)) 在Pipeline.php第103行中调用_user_func(对象(闭包)、对象(请求)) 在Router.php第726行的Pipeline->then(object(Closure))中 在Router.php第699行中的Router->runRouteWithinStack(对象(路由)、对象(请求)) 在Router.php第675行的Router->dispatchToRoute(对象(请求))处 在Kernel.php第246行的Router->dispatch(object(Request))处 在内核->照亮\基础\ Http{closure}(对象(请求)) 在Pipeline.php第52行中调用_user_func(对象(闭包)、对象(请求)) 在checkformintenancemode.php第44行的管道->照明\路由{closure}(对象(请求)) 在CheckFormIntenanceMode->handle(对象(请求)、对象(关闭)) 在Pipeline.php中调用_user_func_数组(数组(对象(checkformintenancemode),'handle')、数组(对象(请求)、对象(闭包)) 第136行 在管道->照明\管道{closure}(对象(请求)) 在Pipeline.php第32行中调用_user_func(对象(闭包)、对象(请求)) 在管道->照明\路由{closure}(对象(请求)) 在Pipeline.php第103行中调用_user_func(对象(闭包)、对象(请求)) 在Kernel.php第132行的Pipeline->then(object(Closure))中 在Kernel.php第99行的Kernel->sendRequestThroughRouter(对象(请求))处 在index.php第54行的Kernel->handle(对象(请求))处 在server.php第21行中的require_once('/Applications/XAMPP/xamppfiles/htdocs/ULTest/public/index.php')

请看这里:

您需要添加CSRF-TOKEN

您可以在表单中添加隐藏输入,如下所示:

<input type="hidden" name="_token" value="<?php echo csrf_token(); ?>">
看看这里:

您需要添加CSRF-TOKEN

您可以在表单中添加隐藏输入,如下所示:

<input type="hidden" name="_token" value="<?php echo csrf_token(); ?>">
最短答案:

{!!csrf_field()!!}

请参阅。

最短答案:

{!!csrf_field()!!}


请参阅。

如果所有配置都正确,请尝试此操作。 我也遇到过这个问题,并采纳了太多的建议,但最后,下面的建议对我来说效果不错

php artisan cache:clear

php artisan config:clear

php artisan config:cache

如果所有配置都正确,请尝试此操作。 我也遇到过这个问题,并采纳了太多的建议,但最后,下面的建议对我来说效果不错

php artisan cache:clear

php artisan config:clear

php artisan config:cache

在应用程序中定义HTML表单时,应在表单中包含隐藏的CSRF令牌字段,以便CSRF保护中间件可以验证请求

您可以使用@csrf Blade指令生成令牌字段:

<form method="POST" action="/someurl">
    @csrf
    ...
</form>

@csrf
...
您可以在laravel文档网站上了解更多信息:

无论何时在应用程序中定义HTML表单,都应该在表单中包含隐藏的CSRF令牌字段,以便CSRF保护中间件可以验证请求

您可以使用@csrf Blade指令生成