你XSRF令牌丟失。默認情況下,新的Laravel應用程序中的所有路由都已打開CSRF保護。
您需要通過設置_token
將有效令牌添加到POST請求標頭或POST數據本身。
如果您只需測試POST路由本身,您可以暫時禁用CSRF中間件,或者在個案基礎上應用它。
禁用
應用程序/ HTTP/Kernel.php
protected $middlewareGroups = [
'web' => [
\App\Http\Middleware\EncryptCookies::class,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
\Illuminate\Session\Middleware\StartSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
//\App\Http\Middleware\VerifyCsrfToken::class, //Comment this out
],
'api' => [
'throttle:60,1',
],
];
/**
* The application's route middleware.
*
* These middleware may be assigned to groups or used individually.
*
* @var array
*/
protected $routeMiddleware = [
'auth' => \App\Http\Middleware\Authenticate::class,
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
];
啓用如路線中間件
應用程序/ HTTP/Kernel.php
protected $middlewareGroups = [
'web' => [
\App\Http\Middleware\EncryptCookies::class,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
\Illuminate\Session\Middleware\StartSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
],
'api' => [
'throttle:60,1',
],
];
/**
* The application's route middleware.
*
* These middleware may be assigned to groups or used individually.
*
* @var array
*/
protected $routeMiddleware = [
'auth' => \App\Http\Middleware\Authenticate::class,
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
'csrf' => \App\Http\Middleware\VerifyCsrfToken::class, //Move it here
];
您需要檢查日誌文件。也許你遇到了問題http://laravel.com/docs/5.1/routing#csrf-protection –
尋求調試幫助的問題(「爲什麼不是這個代碼工作?」)必須包括所需的行爲,特定的問題或錯誤和在問題本身中重現它所需的最短代碼。沒有明確問題陳述的問題對其他讀者無益。請參閱:如何創建一個最小化,完整和可驗證示例.http://stackoverflow.com/help/mcve – Ross