2017-10-17 204 views
1

我有下面的代码块:显示如何添加CSRF令牌ID重定向() - >操作

return redirect()->action('[email protected]', 
       [ 
        'data0' => $request->data0, 
        'data1' => $request->data1, 
        'data2' => $request->data2, 
        'data3' => $request->data3, 

]); 

错误:MethodNotAllowedHttpException可能是因为CSRF令牌不通过这条路线是一种布线后通过。

Route::post('congrats', '[email protected]'); 

我不希望在URL中显示data0,data1等值,所以这就是为什么我希望它是一个POST。

如何在重定向动作上传递csrf标记?有其他方法吗?例如使用GET,但隐藏特定的数据?

+0

怎么样的数据闪烁的会话,并让他们对你重定向到动作可用? – Andreas

回答

1

编辑您的VerifyCsrfToken类这样的禁用验证你的路线

protected $except_urls = [ 
     'contact/create', 
     'contact/update', 
     ... 
    ]; 

public function handle($request, Closure $next) 
{ 
    $regex = '#' . implode('|', $this->except_urls) . '#'; 

    if ($this->isReading($request) || $this->tokensMatch($request) || preg_match($regex, $request->path())) 
    { 
     return $this->addCookieToResponse($request, $next($request)); 
    } 

    throw new TokenMismatchException; 
} 

而在内核更改为指向新的中间件:

protected $middleware = [ 
... 

    'App\Http\Middleware\VerifyCsrfToken', 
]; 

source

编辑

在laravel文档

它添加到VerifyCsrfToken

protected $except = [ 
     'stripe/*', 
    ]; 
+0

有没有编辑'VerifyCsrfToken'或其他的解决方案吗? –

+0

您可以禁用验证Csrf令牌,然后为所有其他路由创建一个路由组 –