Gate after/before and multiple guards #47924
Unanswered
robert-abram
asked this question in
Q&A
Replies: 1 comment
-
I also use multi-auth, and I resolved it by setting the argument type to /**
* Register any authentication / authorization services.
*/
public function boot(): void
{
Gate::before(function (Authenticatable $user, string $ability) {
if (get_class($user) === Admin::class) {
if ($user->isAdministrator()) {
return true;
}
}
if (get_class($user) === User::class) {
...
}
return null;
});
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
I have 2 guards, web and admin. Is it possible to define to what guard Gate::before and Gate::after should be triggerd ?
This Gates in AuthServiceProvider throw error, because if i log in in guard web, then it's say that $admin it's not Admin model but User model, and it's true. Of course i can check inside before and after if $user, or $admin is instance of Model, but maybe there is a way to mark this only for some guards ??
Beta Was this translation helpful? Give feedback.
All reactions