Roles on pivot table
What I am trying to do:
Roles are handled by spatie/laravel-permission.
I have two models with different roles in my project. One is User and one is OrganisationUser (pivot table between the User & Organisation). I want to show and edit this role in the relationship manager that I made for the OrganisationResource.
What I did:
I tried to make a text column with the name 'pivot.roles.name' because just 'roles.name' works for the UserResource. Eventually I made an attribute called rolesNames in OrgansationUser by doing 'pivot.rolesNames' I am able to show roles correct in the relationshipmanager. But this does not fix editing roles.
My issue/the error:
I can't seem to edit roles in the relationship manager. If I make a select the same way I did in the UserResource, it takes the roles from user. I want it to take the roles from the pivot table (OrgansationUser).
Code:
UsersRelationshipManager.php
OrganisationUser.php
6 Replies
Does print out the roles json but
pivot.roles.name
returns nothing
Creating your own edit action and reproducing relationship functionality works but is quite ugly:
Why not use #althinect-spatie-roles-permissions
@toeknee roles are on the pivot table between Users and Organisations so that users are can only do certain stuff within that organisation. This is different from having a role on User.
And that's exactly why you use the teams features of the package. One team = Users, other = Organisations. Then roles are assigned per user, per 'team'
@toeknee I thought the teams feature was supposed to be used for a multi-tenant setup?
Sure is, but that's essentially what you are doing. But just using two tenants.