Team Permission doesn't work for why? #2483
Unanswered
carveybunt
asked this question in
Q&A
Replies: 2 comments 11 replies
-
is |
Beta Was this translation helpful? Give feedback.
2 replies
-
For some mysterious reasons, at least for me, when using Gate::before(function ($user, $ability) {
return $user->hasRole('Super Admin') ? true : null;
}); Always returns false, even tough I created my role with {
"id" : 1,
"team_id" : null,
"name" : "Super Admin",
"guard_name" : "web",
"created_at" : "2023-09-19T19:08:55.000Z",
"updated_at" : "2023-09-19T19:12:41.000Z"
} The only thing I could suppose is that To anyone with the same problem, I created this function inside the User model public function isSuperAdmin(): bool
{
$isSuperAdmin = DB::table('model_has_roles')
->leftJoin('roles', 'model_has_roles.role_id', '=', 'roles.id')
->where('model_has_roles.model_type', '=', User::class)
->where('model_has_roles.model_id', '=', $this->id)
->where('roles.name', '=', config('constants.roles.super_admin')) // I defined some constant to re-use through the system
->whereNull('roles.team_id')
->exists();
return $isSuperAdmin;
} |
Beta Was this translation helpful? Give feedback.
9 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.
-
macOS: 12.5
laravel: 10.10
permission: 5.10
I enable
team
inConfig/permission.php
, and then migrate. In addition, I created the middleware fileTeamSpermission
, as shown in the document. And add it to$middlewarePriority
inapp/Http/Kernel.php
.I already defined a Super-Admin in
AuthServiceProvider.php
, the following:I check permission via the middleware of the route.
I got an error when I used super-admin or other users. Error following:
Where is my code or operation wrong? Someone can help me, please?
Beta Was this translation helpful? Give feedback.
All reactions