Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Ahmed Alaa's avatar

How can I put data in new session after expiration of old one?

I want to get data from the database and put it in session only when a new session is created, can I do that? in another word, I want to make something like an event listener that fires with new session creation.

0 likes
4 replies
Ahmed Alaa's avatar

Thanks for replying :) But my problem is I want to add to the session only after the expiration of the old session

Niush's avatar
Niush
Best Answer
Level 50

Isn't simply doing this good enough. May be even in a middleware.

if ( $request->session()->missing('my_key') ) {
    $request->session()->put('my_key', 'my_value');
}
1 like

Please or to participate in this conversation.