Access To Authenticated User in Error Pages
In Laravel, if you want to edit the default error pages, and for some reason you want to access to currently authenticated user, for example to use a dropdown, or logout, you won't be able to do so.
Let's follow this small tutorial on how to fix that.
In order to fix this annoying problem, all you have to do is append the web middleware.
So first thing, is head to bootstrap/app.php
.
After that, you will see withMiddleware
function, inside the callback function, add the following code :
->withMiddleware(function (Middleware $middleware) {
$middleware->append(StartSession::class);
$middleware->append(ShareErrorsFromSession::class);
})
NOTE: This tip won't go good with Livewire, but I'll investigate and see.
Of course, you have to import those classes.
And you are good to go ♥