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

mallaury's avatar

Session()->put() do not persist...

Hello,

I am using a middleware that check if the user stored his information in session. This middleware works fine and the user model is correctly stored in session, using : Session()->put('user', $user) When the user update his information, I need to refresh it in the session. So I do :

// Update user in DB...
// Then
Session()->forget('user')
Session()->put('user', $user)
// dd(session()->all()) : here I can see the new information stored

But when I redirect the user, the new information do not persist... I checked the middleware and I do not think it delete any data...

Thanks for you help!

0 likes
2 replies
Snapey's avatar

Why do you need user data in session when it is always loaded via auth() ?

Comment out the forget statement. its redundant.

mallaury's avatar

@Snapey Yes I used forget to be sure. I simply need a phone number without any verification, registration, etc. So I thought it is easier to use a middleware

Please or to participate in this conversation.