How to manage roles of users for a model #12606
Unanswered
nilskretschmer
asked this question in
Help
Replies: 1 comment
-
Adding |
Beta Was this translation helpful? Give feedback.
0 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.
-
Package
Panel builder
Package Version
v3.2.71
How can we help you?
Hi,
I am trying to set up Filament to manage the roles of users in my application. Roles can also be attached to some models (in this case a
Project
-Model). The relationships are set up like this:As you can see I also use Staudenmeir's
HasManyDeep
-Package.With this setup I can attach a User to a Role that is also attached to a Project.
Now I am trying to attach/detach users to a project through their roles. A user can either be an
admin
or anuser
of a project (through the role).For this I created a
UsersRelationManager
:Which looks like this in the frontend:
If I now edit a user I get a nice form modal with the current role in the select box:

The problem now:
If I use the
Select
-Field in the form withoutmultiple()
I get this exception:Add fillable property [roles] to allow mass assignment on [App\Models\User].
I think this is because Filament determines the type of relationship based on the
multiple
-option and so assumes a BelongsTo and not a BelongsToMany-Relation. If I addmultiple
I have a select field for multiple roles - but I do not want to achieve that. In this case the UI would be misleading. I only want a user to have one of the roles in the project (but he can have different roles on other projects, thus making it many-to-many).But the even bigger problem is that the user is only attached to that specific role that was selected and DETACHED FROM ALL OTHER ROLES. I went through Filament's documentation but I did not find any way to handle the attaching/detaching. It seems like Filament is calling Laravel's
sync
-method instead of attaching/detaching the user from roles?Beta Was this translation helpful? Give feedback.
All reactions