The problem
When displaying HTTP error pages (404, 500 and so on), I want to keep the standard design of my current project, including header and footer. My project also includes a registration system. When a user is logged in and receives an error message, he will be redirected to the corresponding error page, but Laravel does not recognize that the user is logged in. That's because custom error pages (located in resources/views/errors/{code}.blade.php
don't run through the normal web middleware (for some reasons).
This behavior was already reported a few times, but no sufficient answer was provided. A hacky solution is to set the StartSession
middleware to be applied on every request, but this isn't sufficient in my case.
How can I use the Auth/Session middleware on custom error pages anyway?
Solutions that do not fit
- I don't want to add the
StartSession
middleware (or any other) to every request
Related questions and links
- Laravel Auth in error pages, Laravel 5.0 custom 404 does not use middleware -> Solution is not wanted
- Laravel 5.2 Auth::check() on exception pages (layouts) No good solution
- A GitHub issue I opened, because I think that this behavior is not intentional