Using Laravel 11, exception handling is moved to the bootstrap/app.php
file. I’m trying to catch AuthorizationException
and pass the user back to the dashboard with the 403 message:
// bootstrap/app.php
use IlluminateAuthAccessAuthorizationException;
return Application::configure(basePath: dirname(__DIR__))
...
->withExceptions(function (Exceptions $exceptions) {
$exceptions->render(function (AuthorizationException $e, Request $request) {
return redirect()
->route('dashboard')
->withErrors($e->getMessage());
});
...
})
...
->create();
But it’s not working. This logged in user is gated from seeing the /users
endpoint, but it’s not being handled by my exception handler. They should be seeing their dashboard. (My .env
does show APP_DEBUG=true
.)