Asked  7 Months ago    Answers:  5   Viewed   49 times

In new laravel I can't get session in constructor. Why?

public function __construct()
    dd(Session::all()); //this is empty array

and then below

public function index()
    dd(Session::all()); //here works

In old laravel i remember there was not this problem. something changed?



You can't do it by default with Laravel 5.3. But when you edit you Kernel.php and change protected $middleware = []; to the following it wil work.

protected $middleware = [

protected $middlewareGroups = [
    'web' => [

    'api' => [

Hope this works!

Wednesday, March 31, 2021
answered 7 Months ago

It's worth noting that Laravel actually only stores active sessions in the session folder; those that are 'remembered' but haven't been actively accessing your application do not count among these sessions. As such, just deleting the files won't finish the job.

You must also clear all Remember Tokens from the users table, as this token is used in conjunction with the local token stored in the cookie to re-create the session when a user reconnects.

Wednesday, March 31, 2021
answered 7 Months ago

In order to get remember me functionality you shouldn't work with session configuration. Instead, you should use the functionality already built into Laravel.

When you authenticate user with Auth::attempt(), you can pass a boolean value as the second argument. Set it to true, if user checked remember me checkbox. Set it to false otherwise.

This way, when checkbox is checked, user will be remembered till they manually log out of application. Otherwise, they'll be remembered till they close the browser or session expires.

You can find some more informaton here:

Wednesday, March 31, 2021
answered 7 Months ago

You need to use the Auth facade in the controller;

add this line just before class definition.

use Auth;
Saturday, May 29, 2021
answered 5 Months ago

If you have the subdomains hosted on different physical machines, setting the domain in app/config/session.php to this:

'domain' => ''

will work as long as the two apps will be able to access a shared session data storage (for example using the database session driver and having a common database that stores the sessions).

Tuesday, August 3, 2021
answered 3 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :