中间件位置:app/Http/Middleware/
加载中间件:bean
'httpDispatcher' => [ // Add global http middleware 'middlewares' => [ AppHttpMiddlewareFavIconMiddleware::class, SwoftHttpSessionSessionMiddleware::class, // SwoftWhoopsWhoopsMiddleware::class, // Allow use @View tag SwoftViewMiddlewareViewMiddleware::class, AppHttpMiddlewareAuthMiddleware::class ], 'afterMiddlewares' => [ SwoftHttpServerMiddlewareValidatorMiddleware::class, AppHttpMiddlewareAfterMiddleware::class ] ],
前置中间件
位置:app/Http/Middleware/AuthMiddleware.php
应用场景:权限检测、IP黑名单
后置中间件
位置:app/Http/Middleware/AfterMiddleware.php
应用场景:访问日志、记录请求参数、统计接口请求次数