nova-permission
nova-permission copied to clipboard
Assign Permissions for pivot model
I need to assign different permissions for users based on their teams (a user can join several teams, so he can have different permissions in each team).
In order to achieve this app wise, I created a Pivot Model TeamUser and added the HasRole trait, I also edited the User Model according to this, so permissions are assigned by Spatie package for user-team association.
However I need to assign these permissions on nova too (basically it should be added as a fiekd for the BelongToMany nova relation field) but I have no idea on how to achieve this.
I thought I was really close to solving the same issue tonight, but I get the following error when I try to save the person's team roles.
[07:19:01] LOG.error: Argument 1 passed to Vyuldashev\NovaPermission\RoleBooleanGroup::Vyuldashev\NovaPermission{closure}() must be an instance of Illuminate\Support\Collection, null given {"userId":2,"exception":{}}
The way I got the team role selection to show up on both sides of the relationship was to create a class and then add it on both BelongsToMany() calls.
On the Account resource: BelongsToMany::make('People')->fields(new AccountPersonFields) On the Person resource: BelongsToMany::make('Account')->fields(new AccountPersonFields)
Hi @annis-souames can you please share with us the codebase of (user_team) and (user) model. Thanks
I made it work (at least saving and updating) using the following code (includes PHP 8 features):
RoleSelect::make('Role', 'roles', function (?Collection $roles) {
return $roles?->first()?->name;
}),
If you add this on both the Team and User resource it will show you the Role field in the BelongsToMany relationship table when viewing the resource in detail.