Support the ongoing development of Laravel.io →
posted 10 years ago
Authentication
Last updated 2 years ago.
0

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.

Last updated 2 years ago.
0

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

Last updated 2 years ago.
0

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.

Last updated 2 years ago.
0

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

Last updated 2 years ago.
0

Ah, my bad - I had ! empty and changed it to count, forgot to remove the !

Glad you got it sorted out, happy to help :)

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

kay899 kay899 Joined 7 Jul 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.