Laravel11有没有办法在不重写Authenticate中间件的情况下直接捕获AuthenticationException异常类?
我想实现类似下面的效果,捕获以后自定义响应。9/10版本的时候都是重写Authenticate全局中间件,11中有没有更简单的方式
return Application::configure(basePath: dirname(__DIR__))
->withRouting(
web: __DIR__.'/../routes/web.php',
api: __DIR__.'/../routes/api.php',
commands: __DIR__.'/../routes/console.php',
health: '/up',
)
->withMiddleware(function (Middleware $middleware) {
})
->withExceptions(function (Exceptions $exceptions) {
$exceptions->report(function (\Illuminate\Auth\AuthenticationException $e) {
// 自定义处理
})->stop();
})->create();