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

gouseferoz's avatar

How can i get the guard name of a login session?

Hello Everyone, I have created multiple guards in my app and i want to know the guard name of the user who is logged in and based on that i will redirect the page after user logs out from my app.

Can anyone help me how to find it?

0 likes
1 reply
hupp's avatar

@gouseferoz i think there is no any direct function, but you can do it with first all configured guards and check one by one with the Auth. Hope this works for you.

$guards = array_keys(config('auth.guards'));
foreach ($guards as $guard) {
    if (Auth::guard($guard)->check()) {
        // $guard is the name of the guard that has authenticated the user
        // You can now perform your redirect based on $guard
    }
}

Please or to participate in this conversation.