title: Check if row exists, Laravel
body: <p>I have the following db structure:</p>
  
  <pre><code>items:
  id, name, user_id
  
  users table:
  id, name
  
  user_favorites table:
  id, user_id, item_id
  </code></pre>
  
  <p>On my items permalink pages, I have an 'Add to favorites' button which inserts a new row into <code>user_favorites</code></p>
  
  <p>I want to be able to replace it for a 'Remove from favorites' button if the user already has it in their favorites.</p>
  
  <p>I can't figure out the logic behind this - do I need to check if a row exists in <code>user_favorites</code> that has the current user's id and the permalink item id? This did not work for me:</p>
  
  <pre><code>if (Auth::user()-&gt;id) {
      if (!is_null(DB::table('user_favorites')-&gt;where('user_id', '=', Auth::user()-&gt;id)-&gt;where('item_id', '=', $item-&gt;id)-&gt;first())) {
          // remove from favorites button will show
      }
  }
  </code></pre>