title: Using Laravel whenLoaded() deeper than one level
body: <p>How do I use <a href="https://laravel.com/api/5.5/Illuminate/Http/Resources/ConditionallyLoadsAttributes.html#method_whenLoaded" rel="noreferrer">whenLoaded()</a> for deeper than one level relations? It seems as if one can only use <code>whenLoaded</code> with the first relation depth like this:</p>
  
  <pre><code>'season' =&gt; $this-&gt;whenLoaded('origin', function () {
      return new SeasonResource($this-&gt;origin-&gt;season);
  }),
  </code></pre>
  
  <p>But then Laravel, if <code>origin</code> is loaded, but not <code>season</code>, Laravel will load it, which creates an N+1 problem. Both <code>origin</code> and <code>season</code> relationships are conditional, and not always used. Therefor I want to use something like this:</p>
  
  <pre><code>$this-&gt;whenLoaded('origin.season', ...)
  </code></pre>
  
  <p>or this:</p>
  
  <pre><code>'season' =&gt; $this-&gt;whenLoaded('origin', function () {
       return new SeasonResource($this-&gt;origin-&gt;whenLoaded('season'));
  }),
  </code></pre>
  
  <p>Neither of these work. I suppose the deeper relations are not stored on the model itself, and in the second case, <code>whenLoaded()</code> does not exists on the query builder.</p>
  
  <blockquote>
    <p>How do I use <a href="https://laravel.com/api/5.5/Illuminate/Http/Resources/ConditionallyLoadsAttributes.html#method_whenLoaded" rel="noreferrer">whenLoaded()</a> for deeper than one level relations?</p>
  </blockquote>