之前因为自己自定义了后台的路由,然后路由定义的乱七八糟的。 突然发现session失效了,记录一下,避免后者遇坑。
路由组统一通过web中间件或者存在于一个中间件中
protected $middlewareGroups = [
'web' => [
AppHttpMiddlewareEncryptCookies::class,
IlluminateCookieMiddlewareAddQueuedCookiesToResponse::class,
IlluminateSessionMiddlewareStartSession::class,
// IlluminateSessionMiddlewareAuthenticateSession::class,
IlluminateViewMiddlewareShareErrorsFromSession::class,
AppHttpMiddlewareVerifyCsrfToken::class,
IlluminateRoutingMiddlewareSubstituteBindings::class,
],
'api' => [
'throttle:60,1',
'bindings',
],
];
如上,不同组之间的session不一致
Route::group(['middleware'=>'web'],function (){
.....
所以,如果数由文件拆分之后,共享 Session 的数由组之间,应当拥有共同的 Middleware 如 web