how to get session in databse by user_id and set that for another user in laravel?

400 Views Asked by At

I have saved my session in database, Now I want to get the shopping cart session of special user by user_id after scanning a qrcode and set that shopping cart session for Auth::user().

as you know, the session table in databse have these fields: id, user_id, ip_address, user_agent, payload, last_activity

how to access the $cart = session()->get('cart'); by user_id ?

1

There are 1 best solutions below

0
Rajeev Singh On

You should change the session_driver in config\session.php from the file to a database like:

'driver' => env('SESSION_DRIVER', 'database'),

and created the sessions table

php artisan session:table

and also change your .env file SESSION_DRIVER=database

After that DB session will work and you can check in our DB and you can manage it accordingly.