web中间件从5.2.27版本以后默认全局加载,不需要自己手动载入,如果自己手动重复载入,会导致session无法加载等情况。
下面是Laravel默认为我们提供的web和api中间件组的代码:
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,
],
'api' => [
'throttle:60,1',
],
];