1

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 Commented Aug 29, 2019 at 19:38

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.