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();
自己push一个全局的中间件捕获,类似这种
github.com/deatil/larke-admin/blob...
给你参考,再使用一下异常类接管
我是在
handler.php
处理的,这是 laravel10 的处理方式,laravel11 项目不清楚。瞅下这个。错误处理《Laravel 11 中文文档》
修改 bootstrap/app.php
自定义一个 handler 然后处理