title: Laravel Eloquent's ->load() With Callback Not Affecting Resultset
body: <p>I am looking to take a parent object (<code>Person</code>, in this example) and load a bunch of relationships on it, many of which have custom query parameters passed to <code>-&gt;load()</code> as a callback. For example:</p>
  <pre><code>public function some_method(Request $request, Person $person) {
  
  $person-&gt;load([
     'things' =&gt; function ($query) {
        $query-&gt;where('status', 'active')
           -&gt;whereDate('created_at', '&lt;', '2021-01-01');
     },
     'other_things' =&gt; function ($query) {
        $query-&gt;where('status', 'active')
           -&gt;where('color', 'red');
     },
     ... Many more callback-based relationships ...
  ]);
  </code></pre>
  <p>When I pass this to a Blade template with <code>return view('...', compact('person'))</code> and begin looping over some of the relationships like this:</p>
  <pre><code>@foreach ($person-&gt;things as $thing)
  {{ $thing-&gt;status == 'active' ? 'Active' : 'Inactive' }}
  @endforeach
  </code></pre>
  <p>I get many <code>Thing</code>s that are inactive and do not conform to the <code>-&gt;whereDate()</code> query from the <code>-&gt;load()</code> function in the controller. I would expect the custom callbacks in the <code>load([...])</code> to filter the resulting relationship, but when accessing the relationships in Blade templates, it seems the query is executed as if there are no callback functions present.</p>
  <p>I have tried using <code>with()</code> but that does not appear to be the correct way to approach it, considering I am injecting the <code>Person</code> in the URI. I have also tried using <code>-&gt;map()</code> with various loop structures, but those also get overwritten by what appears to be a second round of Eloquent calls to the database.</p>
  <p>What do I need to do in order to have the Blade template &quot;respect&quot; the custom callback queries that I wish to use to filter the records loaded onto the parent object?</p>
  <p>Thanks!</p>