I am using file based Laravel session.
When running below code:
Session::forget('member');
Session::flush();
Session::regenerate();
The old session wasn't flush at all, all the data including the member info is still there. But the newly generated session start fresh.
How can I really flush the old session before moving to new session?
I believe flush() clears the content of the session, but does not automatically persist the changes. They are persisted at the end of the current request, however, the call to regenerate() will start a new session, and that is the session that is persisted. Could you try to sneak in a call to Session::save(); after Session::flush();?
It also looks like the regenerate method accepts an optional boolean to destroy the session. So possibly, Session::regenerate(true); would help. If that is the case, then flush would probably be unnecessary.
@sisve Thanks for pointing out. Session::save() does the trick.
@devcircus Session::regenerate(true) does clear the old session file, but doesn't clear the previous session data if you didn't flush. Thus, below is my new code:
Session::flush();
Session::regenerate(true);
Thank you for your help. Have a nice day.