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

junaid1's avatar

Get session ID of current logged in user

I am storing sessions in the db. How can I get the current logged in user's session id. Some will say that you can do something like this: Session::where('user_id',Auth::user()->id)->get();

But if the user is also logged in from somewhere else then I will have 2 session id's how can I determine which one is the current user executing the code right now.

0 likes
1 reply
XavRsl's avatar

You should probably not allow for storing multiple session ids per user in the DB. Maybe you should have a one to one relationship between user and session tables.

Please or to participate in this conversation.