2015-10-02 116 views
1

我是新來laravelTokenMismatchException在laravel

我想改變發送多形式要求laravel後註釋狀態

{!! Form::open(['method'=>'patch','onchange'=>'submit()','action'=>['[email protected]',$item->id]]) !!} 
{!! Form::select('show',[0 =>'No',1 =>'Yes' ], $show_view) !!} 
{!! Form::close() !!} 

表明我這個錯誤

TokenMismatchException in VerifyCsrfToken.php line 53: 

in VerifyCsrfToken.php line 53 
at VerifyCsrfToken->handle(object(Request), object(Closure)) 
at call_user_func_array(array(object(VerifyCsrfToken), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124 
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in ShareErrorsFromSession.php line 54 
at ShareErrorsFromSession->handle(object(Request), object(Closure)) 
at call_user_func_array(array(object(ShareErrorsFromSession), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124 
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in StartSession.php line 62 
at StartSession->handle(object(Request), object(Closure)) 
at call_user_func_array(array(object(StartSession), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124 
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in AddQueuedCookiesToResponse.php line 37 
at AddQueuedCookiesToResponse->handle(object(Request), object(Closure)) 
at call_user_func_array(array(object(AddQueuedCookiesToResponse), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124 
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in EncryptCookies.php line 59 
at EncryptCookies->handle(object(Request), object(Closure)) 
at call_user_func_array(array(object(EncryptCookies), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124 
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in CheckForMaintenanceMode.php line 42 
at CheckForMaintenanceMode->handle(object(Request), object(Closure)) 
at call_user_func_array(array(object(CheckForMaintenanceMode), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124 
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) 
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103 
at Pipeline->then(object(Closure)) in Kernel.php line 122 
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 87 
at Kernel->handle(object(Request)) in index.php line 54 
+0

什麼laravel版本,你呢?在5中,您需要在表單中生成一個令牌! – MozzieMD

+0

@MozzieMD它的5.1我添加了令牌,但它沒有工作 –

+0

你檢查HTTP請求標頭嗎?是否發送了「_token」命名值?還是你有正確的HTTP頭,即「X-CSRF-TOEKN」集? – revo

回答

1

你必須將表單中的令牌提交(用於防止CSRF攻擊)。

如果您在Laravel 5,使用

{!! csrf_field() !!} 

如果你正在做一個AJAX請求,你可以在頭在這個部分中添加標記X-CSRF-TOKEN 看:http://laravel.com/docs/5.1/routing#csrf-x-xsrf-token

如果您在Laravel 4,你可以在你的表格中使用Form::token()

另一個選項是從哪個不建議CSRF保護排除URI,但如果需要的話可以做到: http://laravel.com/docs/5.1/routing#csrf-excluding-uris

+0

我相信在Laravel 4中它會自動包含帶'Form :: open()'方法的標記。 – ntzm

+0

我已經這樣做了,但它沒有奏效,當我看到螢火蟲的代碼時,它有令牌但鋼鐵顯示我錯誤 –

+0

@natzim是的,與Laravel 5.1相同令牌會自動添加一個「Form: :打開()' – surfer190

相關問題