title: Laravel eloquent sum and count within a query for nested relationships
body: <p><strong>Background</strong></p>
  
  <p>I have 4 tables that have nested relationships with each other. </p>
  
  <pre><code>events 
  contests (foreign key: evt_id)  
  entries (foreign key: con_id) 
  entry_winner (foreign key: ent_id)
  </code></pre>
  
  <p>I was able to get records with relations like this from the <strong>Entry</strong> model. </p>
  
  <pre><code>$accepted = Entry::where("is_canceled", "=", "0")
              -&gt;with(["contest.event", "entryWinner"])
              -&gt;whereHas("contest.event", function($query) {
                  $query-&gt;where('datetime_utc', "&gt;",Carbon::today());
              })
              -&gt;has("entryWinner")
              -&gt;get();
  </code></pre>
  
  <p>So far so good. </p>
  
  <p><strong>PROBLEM</strong></p>
  
  <p>What I want to get from the query is two things within a query. </p>
  
  <ol>
  <li>Total number of records (count)</li>
  <li>Total sum of relation table's column. (sum)</li>
  </ol>
  
  <p>Here's a query that works exactly for me. </p>
  
  <pre><code>SELECT 
      COUNT(*) AS accepted,
      SUM(contests.ent_fee) AS funds
  FROM entries
  LEFT JOIN contests ON contests.id = entries.con_id
  RIGHT JOIN `events` ON `events`.id = contests.evt_id AND `events`.datetime_utc &gt; '2019-11-22 00:00:00'
  RIGHT JOIN entry_winners ON entry_winners.ent_id = entries.id
  WHERE is_canceled = 0;
  </code></pre>
  
  <p>I'm just curious <strong>how to achieve this using Eloquent</strong>. </p>
  
  <blockquote>
    <p>How to use SUM and COUNT at once ??</p>
  </blockquote>