Reputation: 51
AuthService Provider:
public function boot(GateContract $gate)
{
$this->registerPolicies($gate);
$gate->define('show-user', function ($admin) {
return $admin->hasRole('Admin');
});
}
Admin is a Auth Guard
Controller :
public function edit($admin) {
if (Gate::allows('show-user'))
return 'allow';
else {
return 'deny';
}
}
Gate Always returns 'Deny'
I have a repository function doing the same job.
public function checkPermission($admin) {
return $this->auth->hasRole('Admin') || $this->auth->id === $admin->id;
}
Upvotes: 0
Views: 417
Reputation: 41
Why are you comparing $admin->roles
to a string? From the property name looks like it might return more than one role, maybe as a comma-separated string or array? You have to make sure you check that 'Admin' is one of the roles.
For example if it returns an array you can do:
return in_array('Admin', $admin->roles);
Upvotes: 1