title: Show checkbox checked from database in laravel
body: <p>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.</p>
  <p>Code in <code>RoleController.php</code></p>
  <pre><code>    public function edit($id)
  {
    $role = Role::where('id', $id)-&gt;with('permissions')-&gt;first();
    $permissions = Permission::all();
    return view('admin.manage.roles.edit')-&gt;withRole($role)-&gt;withPermissions($permissions);
  }
  </code></pre>
  <p>Below is the code what I have tried:</p>
  <pre><code>@foreach($permissions as $permission)
   &lt;div class=&quot;checkbox checkbox-styled&quot;&gt;
     &lt;label&gt;
      &lt;input type=&quot;checkbox&quot; name=&quot;permissions[]&quot; value=&quot;{{$permission-&gt;id}}&quot; 
      {{ $role-&gt;permissions-&gt;pluck('id') == $permission-&gt;id ? 'checked' : '' }}
      &gt;
      &lt;span&gt;{{$permission-&gt;display_name}}  &lt;em&gt;({{$permission-&gt;description}})&lt;/em&gt;&lt;/span&gt;
  &lt;/label&gt;
  &lt;/div&gt;
  @endforeach
  </code></pre>
  <p>The code is throwing error
  <code>Object of class Illuminate\Support\Collection could not be converted to int</code></p>
  <p>I had tried:</p>
  <p><code>{{ $role-&gt;permissions-&gt;id == $permission-&gt;id ? 'checked' : '' }}</code></p>
  <p>This throws error:</p>
  <p><code>Property [id] does not exist on this collection instance</code></p>
  <p>When I do <code>{{dd($role-&gt;permissions)}}</code>: The following output was given:</p>
  <p><a href="https://i.stack.imgur.com/Mkiqc.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Mkiqc.png" alt="enter image description here" /></a></p>
  <p><a href="https://i.stack.imgur.com/JF9ba.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/JF9ba.png" alt="enter image description here" /></a></p>
  <p>I would be very thankful if anyone could point-out mistake I'm doing here.</p>