web中間件從5.2.27版本以后默認(rèn)全局加載,不需要自己手動(dòng)載入,如果自己手動(dòng)重復(fù)載入,會(huì)導(dǎo)致session無(wú)法加載等情況。
下面是Laravel默認(rèn)為我們提供的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',
],
];