Search code examples
laravelsessionauthenticationlaravel-5.3

Laravel 5.3 Declare global session var after login success


I've got Auth logins set up on my web app and it works correctly. However, after the user logs in I want to set a global variable like so:

// Store a piece of data in the session...
session(['key' => 'value']);

However, I'm a little lost as to where I should declare a variable after the user successfully logs in.

Should I be doing that in the app/http/controllers/auth/logincontroller.php file?


Solution

  • In Laravel 5.3 you can override authenticated() method in app\Http\Controllers\Auth\LoginController.php:

    protected function authenticated()
    {
        session(['key' => 'value']);
    }
    

    In Laravel 5.2 you can override login() method in app\Http\Controllers\Auth\LoginController.php.