Robin Dirksen
Robin Dirksen

Reputation: 3422

Laravel 5.2 no auth::check() when exception

When I'm on a exception page (for example: abort(404);) I can't access the user data.

Normal page (index.blade.php)

normal page (laravel 5.2)

Exception or abort page

abort or exception page (laravel 5.2)

I want the User model also on the exception pages, but how do I do it?

For example:

@if(Auth::check())
    {{ Auth::user()->name }}
@else
    Not logged in
@endif

Upvotes: 0

Views: 142

Answers (1)

devnull
devnull

Reputation: 1928

Open Kernel.php in app/Http/Kernel.php

Move this Classes from $middlewareGroups to $middleware

\Illuminate\Session\Middleware\StartSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,

So you'll have something like

  protected $middleware = [
        \Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
        \Illuminate\Session\Middleware\StartSession::class,
        \Illuminate\View\Middleware\ShareErrorsFromSession::class,
    ];

Upvotes: 1

Related Questions