嘿如果你使用的是laravel 5.2,這對我來說很合適。
將您的控制器放入'網絡'中間件中。 like,
Route::group(['middleware' => 'web'], function() {
//routes here
});
並確保內核文件已註冊中間件類。
/**
* The application's route middleware groups.
*
* @var array
*/
protected $middlewareGroups = [
'web' => [
\Perkweb\Http\Middleware\EncryptCookies::class,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
\Illuminate\Session\Middleware\StartSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
\Perkweb\Http\Middleware\VerifyCsrfToken::class,
],
'api' => [
'throttle:60,1',
],
];
請務必添加'使用Illuminate \ Http \ Request;' –