title: Count and order by relation with Laravel and Eloquent
body: <p>How can I use Eloquent to count the number of <code>comments</code> from a <code>post</code> and order the <code>posts</code> by number of <code>comments</code>?</p>
  
  <p>My code is something like this:</p>
  
  <pre><code>class Post extends Model
  {
      protected $table = 'posts';
  
      public function comments()
      {
          return $this-&gt;hasMany('App\Comment');
      }
  }
  </code></pre>
  
  <p>I need to retrieve a collection of posts ordered by number of comments in an elegant way, thus I would prefer not to use something like <code>DB::select(select count(comment.post_id), post.id from posts left join comments on posts.id = comments.post_id group by post.id order by count(post.id))</code>;</p>