K Arun Singh
K Arun Singh

Reputation: 810

Unable to access sessions in Laravel app\Exceptions\Handler.php

I'm trying to display 404 page based upon user login, for which I'm trying to get the logged in user id from sessions.

But session session()->all() always returns empty array and also auth()->id(); & Auth::id(); are also empty value.

Upvotes: 2

Views: 2133

Answers (1)

Lloople
Lloople

Reputation: 1844

That's because in app/Http/Kernel.php the protected $middleware array doesn't have the middleware for the session.

What you can do is to move the \Illuminate\Session\Middleware\StartSession::class, middleware from the web middlware group to the global $middleware array.

Upvotes: 7

Related Questions