I have tried to update permissions on role, but with no luck. I get "preg_replace(): Parameter mismatch, pattern is a string while replacement is an array" exception. Is this possible after creating role and assigning permissions to it?
Hmm, the parameter mismatch error mostly occurs when arrays get passed in somewhere instead of strings, or some attribute isn't being casted correctly. Could you post some code snippets?
Thanks for prompt response. I don't have snippets, I had to deliver some demo fast, so I ended up looping through all permissions on some role, revoking them, and then looping again through selected permissions (returned from form, via checkboxes) and assigning them again. This looks like a really bad approach, so my question is how do you sync permissions on some role after they have been created? I don't see that part in the docs.
Roles and permissions have a plain Eloquent many-to-many relationship, so you should be able to use the sync method:
$role->permissions()->sync([$permissionA, $permissionB]);
Most helpful comment
Roles and permissions have a plain Eloquent many-to-many relationship, so you should be able to use the
syncmethod: