Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Nosean's avatar

Session Variable after Login Action

I would like to save session variables after login. Unfortunately, I can not find the entry point. Where should I start the session ??? LoginController ??? I use the login system Auth provided by Laravel ...

thank you for your help

0 likes
4 replies
crnkovic's avatar

Override this in LoginController:

/**
     * The user has been authenticated.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  mixed  $user
     * @return mixed
     */
    protected function authenticated(Request $request, $user)
    {
        //
    }

This method is executed after user has been authenticated to the site.

I recommend Jeffrey's videos on Laravel: http://laravelfromscratch.com

Nosean's avatar

Hi,

If I use this code,

    protected function authenticated(Request $request, $user)
    {
        $userdata = $request->session()->put('CompanyName', $user->company_name);
    }

I get the following error message

Argument 1 passed to App\Http\Controllers\Auth\LoginController::authenticated() must be an instance of App\Http\Controllers\Auth\Request, instance of Illuminate\Http\Request given, called in C:\xampp\htdocs\mayWaWi\vendor\laravel\framework\src\Illuminate\Foundation\Auth\AuthenticatesUsers.php on

I do not understand that somehow

Cronix's avatar

Why do you need to when the user object is available globally? You can use {{ auth()->user()->company_name }} wherever you want to display the logged in users company_name, and it's already stored in session. So you're basically duplicating data in session by doing this.

crnkovic's avatar

I recommend learning PHP before starting with Laravel.

You should import the Illumintate\Http\Request to fix this error. Because Request in the parameter is of that type.

Please or to participate in this conversation.