Php Laravel中间件verifyCsrfToken put变量
我需要禁用某些引用的csrf令牌。我怎么能做到 我试过:Php Laravel中间件verifyCsrfToken put变量,php,laravel,Php,Laravel,我需要禁用某些引用的csrf令牌。我怎么能做到 我试过: /** * The URIs that should be excluded from CSRF verification. * * @var array */ protected $except = [ $_SERVER['HTTP_REFERER'] == 'http://example.com' ? '/example' : '', ]; 但me get error:表达式不允许作为字段默认值$,除非字段用于从CS
/**
* The URIs that should be excluded from CSRF verification.
*
* @var array
*/
protected $except = [
$_SERVER['HTTP_REFERER'] == 'http://example.com' ? '/example' : '',
];
但me get error:
表达式不允许作为字段默认值
$,除非
字段用于从CSRF检查中排除指定的URL。如果您想跳过对特定引用方请求的检查,则需要扩展VerifyCsrfToken
中间件类,并提供新的handle
方法,如下所示:
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
*
* @return mixed
*/
public function handle($request, Closure $next)
{
// If request comes from specific referer...
if ($request->headers->get('referer') == 'http://example.com') {
// ... then we append $except with URL to ignore.
$this->except[] = '/example';
}
// After that we pass the control to original method's implementation
// that will perform the check as usual.
return parent::handle($request, $next);
}
不能在类定义中使用表达式。它需要是一个静态值。相反,在_构造方法中指定它