Different Error Pages for Authenticated and Unauthenticated Users in Laravel
Hello everyone,
I'm currently working on a Laravel project where I need to display different error pages depending on whether a user is authenticated or not. Specifically, I want to return different views for authenticated users at $request->is('account/*') route and serve them error views from a different path (i.e. 'errors/auth').
My initial approach was to use Auth::check() in the bootstrap/app.php, but it seems that isn't possible as the request hasn't been fully bootstrapped yet, hence, the session and its states are not yet set up and accessible.
Here's a pseudocode example of what I am trying to achieve:
if ($user is authenticated) {
if ($request is from 'account/*') {
// Show error pages from 'errors/auth' directory
}
} else {
// Show standard 'errors' pages for guests
}
Does anyone know how can I set this up properly in Laravel? Any help or guidance would be greatly appreciated. Thanks in advance!