How can I group permissions, show them to the user and save without exceptions?
What I am trying to do:
I'm using the role/permissions package from Spatie. Each permission has a group and can belong to a role.
I'm trying to display the permissions on the Create + Edit Role page.
What I did:
I tried different layouts and tried to set different relationships.
My issue/the error:
When I save the permissions I get the exception:
Add [permissions] to fillable property to allow mass assignment on [Spatie\Permission\Models\Role].
Code:
6 Replies
It's because you are not attaching the permissions to the record you are trying to save them on the role by the looks of it.
Spatie have great doc's on how to assign permissions. I assume you are assigning them directly? to a roll as a checkbox. You need to mutate the date and don't save the 'permissions' to the role model.
Let me see how we do it
Initially I was wondering if this is the best way to display the permissions per group
Solution
On our EditRole we do the attached.
And on our RoleManagerResource we do:
So this displays them in groups
It is based on the #althinect-spatie-roles-permissions plugin
Ah bad debugging on my part, this fixes my problem: