2017-10-17 91 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令牌,然後爲所有其他路由創建一個路由組 –