title: Laravel's firstOrNew combined with a join?
body: <p>I have a table titled <code>user_buys</code>, that looks something like:</p>
  
  <pre><code>id | item_id | value | date
  </code></pre>
  
  <p>When I want to create a new entry, I check that there is already an entry for the same <code>item_id</code> on the same <code>date</code>, like this:</p>
  
  <pre><code>$entry = UserBuy::firstOrNew(array('item_id' =&gt; $item_id,'user_id' =&gt; Auth::id(), 'date' =&gt; $date));
      $entry-&gt;value = $value;
      $entry-&gt;save();
  </code></pre>
  
  <p>So if an entry exists, just update the <code>value</code> column. But, there's a catch. There is another table titled <code>user_sales</code>, that looks like:</p>
  
  <pre><code>id | buy_id | sale_price
  </code></pre>
  
  <p>where <code>buy_id</code> is the <code>id</code> from <code>user_buys</code>. If the <code>firstOrNew</code> function finds an existing entry for the <code>item_id/date</code> combination, it should also check that it doesn't exist in the <code>user_sales</code> table. So basically I need a <code>leftJoin</code> to check whether the item that was bought has already been sold. In this case, I need to create a new entry in <code>user_buys</code> and not update the existing one.</p>
  
  <p>I could write more convoluted code to do this with about 3 separate queries, but I was wondering if there is a way to make this additional check using the <code>firstOrNew</code> approach.</p>