title: Query builder Eloquent using Eager Loading in Laravel
body: <p>Having a typical squeme with post &amp; comments where a post have many comments and a comment belongs to one post:</p>
  
  <p><strong>Post Model:</strong></p>
  
  <pre><code> public function comments(){
      return $this-&gt;hasMany('App\Comment');
  }
  </code></pre>
  
  <p><strong>post migration:</strong></p>
  
  <pre><code>Schema::create('posts', function (Blueprint $table) {
          $table-&gt;increments('id');
          $table-&gt;string('name');         
      });
  </code></pre>
  
  <p><strong>Comment model:</strong></p>
  
  <pre><code> public function Post(){
      return $this-&gt;belongsTo('App/Post', 'id');
  }
  </code></pre>
  
  <p><strong>Comment migration:</strong></p>
  
  <pre><code>   Schema::create('comments', function (Blueprint $table) {
          $table-&gt;increments('id');
          $table-&gt;date('date_comment');
          $table-&gt;unsignedInteger('post_id')-&gt;nullable()-&gt;default(null);
          $table-&gt;foreign('post_id')-&gt;references('id')-&gt;on('posts');
          });
  </code></pre>
  
  <p>I would like use eager loading in Laravel.</p>
  
  <p>For example. How Can I obtain <strong><em>all posts with his most recent comment</em></strong> using eager loading?</p>
  
  <p>I tried this:</p>
  
  <pre><code>$post = Post::with('comments:post_id, date_comment')-&gt;get();
  </code></pre>
  
  <p>But like this I obtain all comments. Any help please?</p>
  
  <p>Best regards</p>
  
  <p>EDIT:</p>
  
  <p>foreach statement (Blade):</p>
  
  <pre><code>   @foreach($posts as $post)            
              &lt;td&gt;{{ $post-&gt;name }}&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;
              {{ !empty($post-&gt;comments[0]) ? $post-&gt;comments[0]-&gt; 
                  date_comment : '' }}
              &lt;/td&gt;                                      
     @endforeach
  </code></pre>