0
votes

I am trying to store session in the database rather than in file. So in my .env file:-

SESSION_DRIVER=database

& in my config/session.php:-

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

So now after doing:

$request->session()->flush()

to remove session in my controller, the session values are stilled stored in my DB. Although after flushing session in the controller I have checked session key exists or not where it is showing session does not exist, but why session are not deleted from DB? Also in my DB table sessions user_id is showing NULL. Why is that?

Earlier I used to store session in a file. Now I am trying to store session in database. Can anyone please help me.

1
What are you storing in the session? the visitor's information has to remain in session and the user_id is null because you're not authenticated - Salim Djerbouh

1 Answers

2
votes

Old session rows in database will be deleted only after the Session garbage collector is called, the specific function is gc().

This function has a probability to be called on every request, you can control the chances it will run with the session.lottery config value.

But do not worry, even if the session rows are still present in the database they are invalidated after logout (user_id is null), only deletion occur with the gc() function above.

Nor Session::flush() nor Session::regenerate(true) will delete old session rows.