Something like this ought to do the trick. Essentially, iterate through the posted permission identifiers, check that the record exists then, for all (if any), sync them to the role.
Hi deringer,
thanks for your post, but I am afraid that code doesn't store any relation for the permissions at all. :-(
Any idea why?
Regards kay899
Without seeing the form data you're posting, it's hard to say. Throw a dd($valid_permissions)
after the foreach and see if you're getting any result. Also make sure that $input['permissions']
are actually set.
Got it. It must be:
if ( count($valid_permissions) > 0 ) {
$role->permissions()->sync($valid_permissions);
}
Otherwise this method is not fired. :-)
Thanks for your help. kay899
Ah, my bad - I had ! empty and changed it to count, forgot to remove the !
Glad you got it sorted out, happy to help :)
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community