Laravel Auth on error pages

When a user logs in to my application, there is access to access administration in the drop-down list. However, when a user stumbles upon a page with an error (for example, 404), it does not show that they are logged in. Instead, it shows "Login." Why is this?

Here is my code.

@if (Auth::check()) <ul class="nav navbar-nav navbar-right"> <li class="dropdown"> <a style="cursor: pointer;" class="dropdown-toggle" data-toggle="dropdown"><i class="glyphicon glyphicon-user"></i> {{ Auth::user()->name }} <b class="caret"></b></a> <ul class="dropdown-menu"> <li> <a href="/admin/dashboard"><i class="glyphicon glyphicon-tasks"></i> Dashboard</a> </li> <li role="separator" class="divider"></li> <li><a href="/logout"><i class="glyphicon glyphicon-log-out"></i> Logout</a></li> </ul> </li> </ul> @else <ul class="nav navbar-nav navbar-right"> <li><a href="/login"><i class="glyphicon glyphicon-log-in"></i> Login</a</li> </ul> @endif 
+3
php laravel laravel-5
source share
1 answer

It looks like Laravel is just starting a session where he sees the corresponding one (which is not a 404 page), as Daniel pointed out: https://github.com/laravel/framework/issues/11653 .

To combat this (since the navigation bar is for the entire site, including 404 pages), I added the StartSession class to global middlwares.

 protected $middleware = [ \Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class ]; 

Now it becomes ...

 protected $middleware = [ \Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class, \Illuminate\Session\Middleware\StartSession::class ]; 
+3
source share

All Articles