title: Preventing Laravel adding multiple records to a pivot table
body: <p>I have a many to many relationship set up and working, to add an item to the cart I use:</p>
  
  <pre><code>$cart-&gt;items()-&gt;attach($item);
  </code></pre>
  
  <p>Which adds an item to the pivot table (as it should), but if the user clicks on the link again to add an item they have already added it creates a duplicate entry in the pivot table.</p>
  
  <p>Is there a built in way to add a record to a pivot table only if one does not already exist?</p>
  
  <p>If not, how can I check the pivot table to find if a matching record already exists?</p>