title: Laravel eager loading nested relationships with custom query
body: <p>I have the code which works, but without eager loading nested relationships.</p>
  
  <pre><code>$projects = Project::with('organization')
          -&gt;leftJoin('stages', 'stages.project_id', '=', 'projects.id')
          -&gt;leftJoin('activities', 'activities.stage_id', '=', 'stages.id')
          -&gt;leftJoin('tasks', 'tasks.activity_id', '=', 'activities.id')
          -&gt;select('projects.*',  DB::raw('SUM(IF(tasks.status = 4, score, 0)) AS score'), 
                                  DB::raw('SUM(tasks.score) AS total_score'))
          -&gt;groupBy('projects.id')
          -&gt;get();
  </code></pre>
  
  <p>I want to do this with eager loading nested relationships, and if I wouldn't have these custom selects (total_score and score), I would do</p>
  
  <pre><code>$projects = Project::with('stages.activities.tasks');
  </code></pre>
  
  <p>but the problem appears on those custom selects (score and total_score).
  I tried something like that, but didn't work</p>
  
  <pre><code>$projects = Project::with(['stages', 'activities', 'tasks' =&gt; function($q) { 
          $q-&gt;select( DB::raw('SUM(IF(tasks.status = 4, score, 0)) AS score'), 
                      DB::raw('SUM(tasks.score) AS total_score')); 
      }])-&gt;get();
  </code></pre>