Pivot table and user roles

Hi, I am working on a multi-tenancy application in Filament and struggling with pivot table and user roles. Has anyone had a similar problem? https://stackoverflow.com/questions/78328959/change-the-role-for-a-user-using-a-pivot-table-in-laravel-filament tuto1902 great content!
Stack Overflow
Change the role for a user using a pivot table in Laravel Filament
I am stuck with the following problem. I have tables and a pivot model as in this link: https://stackoverflow.com/a/78324280/22428348 What I want is a select field to change a role of the user inside
3 Replies
tuto1902
tuto19023mo ago
I'll look into it and let you know. Allow me a few days to give you an answer.
tuto1902
tuto19023mo ago
The way I'm looking at this (and please correct me if I'm wrong), a user can have different roles in every unit. So, to me, it doesn't make sense to to have a select field to change the role since the user role is related to the unit the user belongs to. Which means that what you probably need is a UnitRelationManager for the UserResource, which let's you manage the units the user belongs to and the role the user has in each unit. Relation managers allow you to load pivot data (ie. role), and that's where you can have a select input. Not in the user resource, but in the UnitRelationManager. Here are the docs for it https://filamentphp.com/docs/3.x/panels/resources/relation-managers#listing-with-pivot-attributes
marinm
marinm3mo ago
Thanks for your answer, Every user that is owner (role) for the current unit (tenant) should change roles for other users in the same unit. But with this approach each user can change the roles for other users. In this case on the image, "test" user is the owner only for the "first-hotel" tenant and the "reader" for the "prvi hotel", it should be forbidden to him to change "reader" on the "prvi hotel"
No description