为什么我在表单里输入数据后,点击提交,结果报错了呢?Whoops, looks like something went wrong. TokenMismatchException in VerifyCsrfToken.php line 46:
你也可以通过将这类 URI 添加到 VerifyCsrfToken 中间件中的 $except 属性来排除对这类路由的 CSRF 保护:
<?php
namespace App\Http\Middleware;
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as Middleware;
class VerifyCsrfToken extends Middleware
{
/**
* Indicates whether the XSRF-TOKEN cookie should be set on the response.
*
* @var bool
*/
protected $addHttpCookie = true;
/**
* The URIs that should be excluded from CSRF verification.
*
* @var array
*/
protected $except = [
//
'student/*',
];
}弱弱的问一句具体加在哪里。
解决了,要在表单域里加 <input type="hidden" name="_token" value="{{csrf_token()}}"/> 原因是:
laravel 默认开启了 csrf验证 ,不是get请求的话需要验证csrf,因此在表单里需要加个隐藏域