Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Need help. How to create session after login with the user details in laravel?

I want to save some details on session when the user login. And the details are retrieved from the same user table that user for Auth(). Do I have to query again after login and set the session variables or there is a way within auth. Thanks in advance! :)

like image 736
Ryu Le Avatar asked Oct 30 '25 08:10

Ryu Le


2 Answers

You can get the currently logged in user with Auth::user(). So, if you wanted to store the user's username in the session after login you could do this:

$user = Auth::user();
Session::put('username', $user->username);
like image 152
CodingAllNight Avatar answered Nov 01 '25 14:11

CodingAllNight


To store user information, You can easily use

    $user = Auth::User();
    Session::put('user', $user);
    $user=Session::get('user');
    return $user->name; 

You must have to put use Session; in controller where you want to set or get the value

here $user is a object you can get all other property using this -> sign.

Thank You

like image 33
Jakarea Parvez Avatar answered Nov 01 '25 14:11

Jakarea Parvez



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!