title: One-to-many then eager load an array with Laravel Eloquent ORM
body: <p>With Laravel and the eloquent ORM, I want to create an array or object of all posts and corresponding comments that belong to a specific user (the logged in one).  The result will then be used with Response::eloquent(); to return JSON.</p>
  
  <p>Basically in pseudo-code:</p>
  
  <pre><code>All Posts by user ::with('comments').
  </code></pre>
  
  <p>or</p>
  
  <pre><code>Posts by Auth::user()-&gt;id ::with('comments').
  </code></pre>
  
  <p>I have my database setup per the usual with a user's table, comments table and posts table.  The comments table has a post_id and the posts table has a user_id.</p>
  
  <p>The long way of doing this without Laravel would be something like:</p>
  
  <pre><code>SELECT * FROM posts WHERE user_id = 'user_id'
  foreach($result as $post) {
      SELECT * FROM comments WHERE posts_id =  $post-&gt;id
      foreach($query as $comment) {
          $result[$i]-&gt;comments[$n] = $comment
      }
  }
  </code></pre>
  
  <p>But I want to accomplish it with Laravel's Eloquent ORM.</p>