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

Moody_Matters's avatar

Multiple Auth sessions using different models.

I have two tables, a login and a user table, each with a corresponding model, and the relationship is one to many.

Currently, I am using Auth::guard('login')->attempt() to create a session for the login model, but would like to have a 'sub' session for the user model, so I can have a different session when changing user, while keeping the login session. For this I have tried Auth::guard('user')->login($user), having set up multiple guards.

Is this possible, and if not is there a solution to achieve a similar affect? A major use case for this is for the user model to be compatible with the spatie laravel-permission package.

I found this when searching, but was not sure if it was considering using different models for each session https: //laracasts.com/discuss/channels/laravel/multiple-simultaneous-auth-sessions'

0 likes
6 replies
Moody_Matters's avatar

If this isn't possible is there an easy way to transfer a session from one model to another?

jlrdw's avatar

Use authentication for ensuring a login and use authorization to determine what a logged in user with role /s can or cannot do.

You are describing it seems two users on same computer. So I don't totally understand what you need.

However you can use a different browser to achieve two different logins. But I suggest don't let each user have their own terminal.

Snapey's avatar

unclear what the business case might be for this

Moody_Matters's avatar

@jlrdw @snapey Thanks for the comments! The use case is there is to be one site with one login that allows a logged-in member to switch between 2 sub-sites holding different data, without having to re-enter credentials. The member has a different user profile for each and may hold different roles or permissions.

The login model uses a guard with a jwt driver. The user model I'd like to also be authenticated when each subsite is selected. This is separate from the login as the user data is owned separately by each subsite.

I hope this helps explain. Given that is there a way to have two authenticated models at the same time? Maybe if I use a different driver for each guard?

newbie360's avatar

OP means look like Firefox tab container ?

in Firefox we can create many tab container for login diff google account ...etc

Moody_Matters's avatar

Thanks for the help, I think I'm going to solve it by changing the authenticated model instance on sub-site selection.

Please or to participate in this conversation.