title: adding multiple scopes to nested eager loading
body: <p>In my application users can predict scores of upcoming soccer games.</p>
  
  <p><em>Basically I want to display all the user predictions for this week. I do this by adding a scope to my match model that only loads matches from this week.</em></p>
  
  <p><strong>Problem: I'm still getting all my predictions from that user (not only the ones from the current week)</strong> For predictions that my user created this week, the correct match is loaded. For the other predictions there is no match but they still get put in my query.</p>
  
  <p><strong>How can I add another scope to my nested eager loading that will only select predictions made during this week or have a match that is not null?</strong> (or other solution)</p>
  
  <p><strong>Code:</strong></p>
  
  
  
  <pre class="lang-php prettyprint-override"><code>public function showPredictions() {
      $user = auth()-&gt;user()-&gt;load(['predictions.match' =&gt; function ($query) { $query-&gt;thisWeek();}]);
      dd($user); 
      return view('predictions', compact('user'));
  }
  </code></pre>
  
  <p><strong>Match model</strong></p>
  
  <pre class="lang-php prettyprint-override"><code>public function Predictions() {
      return $this-&gt;hasMany('App\Prediction', 'match_id', 'match_id');
  }
  
  public function scopeThisWeek($query) {
      $start_date = now()-&gt;previous(Carbon::TUESDAY);
      $end_date = now()-&gt;next(Carbon::MONDAY);
      return $query-&gt;whereDate('date','&gt;', $start_date)-&gt;whereDate('date','&lt;', $end_date);
  }
  </code></pre>
  
  <p><strong>output</strong></p>
  
  <pre class="lang-php prettyprint-override"><code>  #relations: array:1 [▼
      "predictions" =&gt; Collection {#265 ▼
        #items: array:29 [▼
          0 =&gt; Prediction {#268 ▶}
          1 =&gt; Prediction {#269 ▶}
          2 =&gt; Prediction {#270 ▶}
          3 =&gt; Prediction {#271 ▶}
          4 =&gt; Prediction {#272 ▶}
          5 =&gt; Prediction {#273 ▶}
          6 =&gt; Prediction {#274 ▶}
          7 =&gt; Prediction {#275 ▶}
          8 =&gt; Prediction {#276 ▶}
          9 =&gt; Prediction {#277 ▶}
          10 =&gt; Prediction {#278 ▶}
          11 =&gt; Prediction {#279 ▶}
          12 =&gt; etc... 
        ]
  </code></pre>
  
  <p><strong>Output I want to achieve (I have 10 predictions for each user that week)</strong></p>
  
  <pre class="lang-php prettyprint-override"><code> #relations: array:1 [▼
      "predictions" =&gt; Collection {#265 ▼
        #items: array:10 [▼
          0 =&gt; Prediction {#268 ▶}
          1 =&gt; Prediction {#269 ▶}
          2 =&gt; Prediction {#270 ▶}
          3 =&gt; Prediction {#271 ▶}
          4 =&gt; Prediction {#272 ▶}
          5 =&gt; Prediction {#273 ▶}
          6 =&gt; Prediction {#274 ▶}
          7 =&gt; Prediction {#275 ▶}
          8 =&gt; Prediction {#276 ▶}
          9 =&gt; Prediction {#277 ▶}
          10 =&gt; Prediction {#278 ▶}
        ]
  </code></pre>
  
  <p>I have a relation field in my predictions array with the correct match in.</p>