0
I have an ACL app for Laravel where I have two sessions(Guards), one for users and another to admins.
The configuration of Guards auth.php file looks like this:
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'api' => [
'driver' => 'token',
'provider' => 'users',
],
'admin' => [
'driver' => 'session',
'provider' => 'admins',
],
'admin-api' => [
'driver' => 'token',
'provider' => 'admins',
],
],
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => Crebs86\TrustMultiAuth\Model\User::class,
],
'admins' => [
'driver' => 'eloquent',
'model' => Crebs86\TrustMultiAuth\Model\Admin::class,
],
],
The function boot()
of AuthServiceProvider
gets that way:
public function boot()
{
$this->registerPolicies();
$permissions = Permission::with('roles')->get();
foreach ($permissions as $permission):
Gate::define($permission->name, function (User $user) use ($permission) {
return $user->hasPermission($permission);
});
endforeach;
Gate::before(function(User $user, $ability){
if($user->hasAnyRoles('super-admin'))
return true;
});
}
As you can see I can only inject one Guard, in case the web Gate::define($permission->name, function (User $user)...
, and all the logic based on access control works for the login done on model User,.
But I can’t get the Guard of the origin of the request and request the model Admin when this is the case.
Hello. try what I said above! Anything ask here!
– Cleber Martins
Cleber, show caraa!! worked but only with the option $user = null. Ai to get permission from which user was logging in I did in User Model protected $Guard = 'user'; and did the function public Function pegGuard(){ Return $this->Guard; }
– user2227682