title: Comparing two models in Laravel/Eloquent
body: <p>I have the table <code>item_list</code> and the table <code>users</code></p>
  
  <p>I have the pivot table <code>allowed_items</code> that contains <code>item_id</code> from the item_list and <code>user_id</code> from the user table.</p>
  
  <p>I have some checkbox list that should be checked when the item and the user are in the pivot table, and be left unchecked if it does not.</p>
  
  <p>I am currently doing this:</p>
  
  <pre><code>$items = item_list::all();
  $allowed_items = allowed_items-&gt;where("user_id",$user_id")-&gt;get();
  foreach ($allowed_item as $allow)
  {
  $allow_array[$allow-&gt;item_id] = true;
  }
  </code></pre>
  
  <p>Then I return the view and check if the item exists like this:</p>
  
  <pre><code>@foreach($items as $item)
  &lt;input type="checkbox" value="{{$item-&gt;id}} 
  {{array_key_exists($item-&gt;id,$allow_array") ? "checked":" "}}&gt;
  @endforeach
  </code></pre>
  
  <p>This works, but it feels unprofessional. Any way to do this in the controller?</p>