Actually it's a lot easier than you're thinking, all you need to do is something like this...
$role->permissions()->sync(Input::get('permisssions'));
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi,
I try to make an ACL with this Package: https://github.com/Toddish/Verify-L4
To add Permissions to a Role I'll get an array of Roles IDs from my Checkbox area: array(2) { [0]=> string(1) "1" [1]=> string(1) "2" }
No I need to give that to the Role's Permissions in that format: $role->permissions()->sync(array($permission->id, $permission2->id));
Actually I have no idea how to "produce" this: array($permission->id, $permission2->id)
Can someone give me a hint?
Here is my actual code:
public static function postStore($input, $form)
{
$form->specialRules($input)->validate($input);
$role = new Toddish\Verify\Models\Role;
$role->name = $input['name'];
$role->description = $input['description'];
$role->level = $input['level'];
$role->created_by = Auth::user()->id;
$role->updated_by = Auth::user()->id;
$role->save();
if ($input['permissions'])
{
foreach ($input['permissions'] as $key => $value) { $permission = Permission::find($value)->id; $role->permissions()->sync(array($permission->id)); } }
return;
}
Thanks ahammen
Actually it's a lot easier than you're thinking, all you need to do is something like this...
$role->permissions()->sync(Input::get('permisssions'));
Please or to participate in this conversation.