Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assign Permissions for pivot model #149

Open
annis-souames opened this issue Dec 15, 2020 · 3 comments
Open

Assign Permissions for pivot model #149

annis-souames opened this issue Dec 15, 2020 · 3 comments

Comments

@annis-souames
Copy link

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.

@terry-greenlaw
Copy link

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)

@sys-auditing
Copy link

Hi @annis-souames can you please share with us the codebase of (user_team) and (user) model.
Thanks

@dees040
Copy link

dees040 commented Sep 10, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants