title: Can I fake laravel eager loading using a join?
body: <p>I have read several posts on why eager loading uses multiple queries rather than joining <a href="https://stackoverflow.com/questions/23920540/why-cant-laravel-eloquent-use-join-for-eager-loading">here</a>, <a href="https://stackoverflow.com/questions/20780715/how-to-use-eager-loading-and-join-in-eloquent-at-a-same-time-in-laravel-4">here</a>, and <a href="http://laravel.io/forum/04-04-2014-why-two-queries-in-relationships-not-join" rel="nofollow noreferrer">here</a>. However, I have a situation that I think warrants using a join instead of eager loading. How would I construct the query so that I can access the sub-object as if it were a normally eager loaded object?</p>
  
  <p>Example: Getting people that live on a certain street, and loading that address at the same time. I don't want to load all the person's addresses, incase he lives at many places; just the places that match the query. With eager loading and whereHas I have to duplicate the query, and it's not always this simple of a query:</p>
  
  <pre><code>People::with(['address', function($query) use ($street_name){
    return $query-&gt;where('street_name', $street_name);
  }])-&gt;whereHas('address', function($query) use ($street_name){
    return $query-&gt;where('street_name', $street_name);
  })-&gt;get();
  </code></pre>
  
  <p>could be</p>
  
  <pre><code>People::query()-&gt;join('address', function($join){
    $join-&gt;on(...)
  })-&gt;where('street_name', $street_name);
  </code></pre>
  
  <p>The problem then is that I cannot use this:</p>
  
  <pre><code>$person-&gt;address
  </code></pre>
  
  <p>Is there a way to take the join and massage it (using selects?) so that it appears like it was eager loaded?</p>