I am using laravel 10. I have 2 guards. One is admin and another is manager . The Auth only authenticate the default one so in the controller construction I have set
public function __construct(){
Config::set('auth.defaults.guard','admin');
}
public function __construct(){
Config::set('auth.defaults.guard','manager');
}
Now I have to check the user to verify if it’s admin or manager guard but if I check the guard name its says null. auth()->guard('guard_name')->user()->name;
I dont know how can I get the guard name to authenticate!
2
Answers
I have found an idea to solve this issue. When the query successfully executed, setting another value as admin or manager based on their controller and passing the data as array with token.
Instead of setting the guard in the
constructor
you can define directly the guard when authenticating :Then if you want to check if the user is authenticated with specific guard you can use the
check()
method inAuth
Facade.