title: Laravel / Lumen limit 1 in join closure
body: <p>I try to retrieve some data from a table but I need only one item.</p>
  
  <p>Tables:
  reservations, reservation_products, products_price_history.</p>
  
  <p>The table structure is too complex so let's use only what we need:</p>
  
  <p>reservations:</p>
  
  <pre><code>| id | date       |
  -------------------
  | 1  | 2017-10-03 |
  </code></pre>
  
  <p>reservation_products</p>
  
  <pre><code>| id | reservation_id |
  -----------------------
  | 1  | 1              |
  </code></pre>
  
  <p>products_price_history</p>
  
  <pre><code>| id | product_id | start_date | end_date   | price |
  -----------------------------------------------------
  | 1  | 1          | 2017-09-20 | 2017-10-01 | 200   |
  | 2  | 1          | 2017-10-01 | NULL       | 200   |
  </code></pre>
  
  <p>A reservation has many prouducts and a product have many prices. I need to take the price that it's start_date is less than reservation's date. </p>
  
  <p>THe logic:</p>
  
  <pre><code>$users = User::with(['reservations' =&gt; function($query) {
  
      // reservation products
      $query-&gt;with(['reservation_products' =&gt; function($query) {
          $query-&gt;join('reservations', 'reservation_products.reservation_id', 'reservations.id');
          $query-&gt;join('products', 'reservation_products.product_id', 'products.id');
  
          $query-&gt;join('products_price_history', function($query) {
              $query-&gt;on('reservations.salon_id', 'products_price_history.salon_id');
              $query-&gt;on('reservation_products.product_id', 'products_price_history.product_id');
              $query-&gt;on('reservation_products.product_type_id', 'products_price_history.product_type_id');
              $query-&gt;whereRaw('reservations.date &gt;= products_price_history.date_start');
              $query-&gt;limit(1);
          });
      }]);
  
  }])-&gt;get();
  </code></pre>
  
  <p>The <code>$query-&gt;limit(1);</code> is not working. The query just gives me all the entries that are lower than reservations date.</p>
  
  <p>Thanks.</p>