I'm using Laratrust package for ACL in my application. I'm trying to edit roles (assign permissions to role) using checkbox. And want get already assigned permission checkbox state checked from database.
Code in RoleController.php
public function edit($id)
{
$role = Role::where('id', $id)->with('permissions')->first();
$permissions = Permission::all();
return view('admin.manage.roles.edit')->withRole($role)->withPermissions($permissions);
}
Below is the code what I have tried:
@foreach($permissions as $permission)
<div class="checkbox checkbox-styled">
<label>
<input type="checkbox" name="permissions[]" value="{{$permission->id}}"
{{ $role->permissions->pluck('id') == $permission->id ? 'checked' : '' }}
>
<span>{{$permission->display_name}} <em>({{$permission->description}})</em></span>
</label>
</div>
@endforeach
The code is throwing error
Object of class Illuminate\Support\Collection could not be converted to int
I had tried:
{{ $role->permissions->id == $permission->id ? 'checked' : '' }}
This throws error:
Property [id] does not exist on this collection instance
When I do {{dd($role->permissions)}}: The following output was given:
I would be very thankful if anyone could point-out mistake I'm doing here.


$role->permissionsis a collection. Try editing your post, while including your controller.