title: Laravel: Count number of rows in a relationship
body: <p>I have the following relationship:</p>
  
  <ul>
  <li>A venue has many offers</li>
  <li>A offer has many orders</li>
  </ul>
  
  <p>I have the following Eloquent model to represent this:</p>
  
  <pre><code>class Venue {
      public function orders()
      {
          return $this-&gt;hasManyThrough(Order::class, Offer::class);
      }
  }
  </code></pre>
  
  <p>I want to determine the total number of orders for venues with <code>location_id = 5</code> using Laravel's Eloquent model.</p>
  
  <p>The only way I managed to do this is as follows:</p>
  
  <pre><code>$venues = Venue::where('location_id', 5)-&gt;with('orders')-&gt;get();
  
  $numberOfOrders = 0;
  foreach($venues as $venue) {
      $numberOfOrders += $venue-&gt;orders-&gt;count();
  }
  dump($numberOfOrders); // Output a single number (e.g. 512)
  </code></pre>
  
  <p>However, this is obviously not very efficient as I am calculating the count using PHP instead of SQL.</p>
  
  <p>How can I do this using Eloquent model alone.</p>