Applying laravel-permission to a User/Group authorization model (verification of approach) #2314
Unanswered
msacharewicz
asked this question in
Q&A
Replies: 1 comment 5 replies
-
You misunderstood the point of this package, |
Beta Was this translation helpful? Give feedback.
5 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.
-
Our university (and thus, my app) implements a
User::belongsToMany(Group)
relationship, withGroup
model representing specific departments. I've read the docs several times and I am still not sure, how to apply this package against our scenario.In my app, I need to be able to assign specific roles and/or permissions either to a
Group
or a specificUser
, and then, when resolving permissions, I need to check if either theUser
or anyGroup
he belongs to has a specific permission.At first I thought of using the Teams feature, but no matter how hard I read docs, it seems that Teams are implemented as
User::belongsTo(Team)
.This seems to leave me with a solution to add HasRoles trait to both User and Group model and perform checks like:
User->hasPermissionTo(x) || User->groups()->hasPermissionTo(x)
.Or, a nicer approach, to extend HasRoles and HasPermissions traits like:
and
Does it even remotely sound like a correct approach, or is there a better one?
Beta Was this translation helpful? Give feedback.
All reactions