[ // Cookie 加密解密 \App\Http\Middleware\EncryptCookies::class, // 将 Cookie 添加到响应中 \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class, // 开启会话 \Illuminate\Session\Middleware\StartSession::class, // 认证用户,此中间件以后 Auth 类才能生效 // \Illuminate\Session\Middleware\AuthenticateSession::class, // 将系统的错误数据注入到视图变量 $errors 中 \Illuminate\View\Middleware\ShareErrorsFromSession::class, // 检验 CSRF ,防止跨站请求伪造的安全威胁 \App\Http\Middleware\VerifyCsrfToken::class, // 处理路由绑定 \Illuminate\Routing\Middleware\SubstituteBindings::class, RecordLastActivedTime::class, ], // API 中间件组,应用于 routes/api.php 路由文件 'api' => [ // 使用别名来调用中间件 'throttle:60,1', 'bindings', ], ]; /** * The application's route middleware. * 中间件别名设置,允许你使用别名调用中间件,例如上面的 api 中间件组调用 * These middleware may be assigned to groups or used individually. * * @var array */ protected $routeMiddleware = [ //只有登录用户才能访问,我们在控制器的构造方法中大量使用 'auth' => \Illuminate\Auth\Middleware\Authenticate::class, 'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class, // 处理路由绑定 'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class, // 用户授权功能 'can' => \Illuminate\Auth\Middleware\Authorize::class, // 只有游客才能访问,在 register 和 login 请求中使用,只有未登录用户才能访问这些页面 'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class, // 访问节流,类似于 『1 分钟只能请求 10 次』的需求,一般在 API 中使用 'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class, //语言设置 'change-locale' => ChangeLocale::class, ]; }