title: Laravel OrderBy comments in posts
body: <p>I have post and comments tables where of course comments belongs to posts.
  I want to sort posts now with eloquent by amount of comments.
  How can i do that in laravel?</p>
  
  <p>I tried to order by date using:</p>
  
  <pre><code>Post::orderBy('created_at', 'DESC')-&gt;paginate(6);
  </code></pre>
  
  <p>i want the same but sorting by comments with are on other database but they are connected in model.</p>
  
  <p>EDIT:</p>
  
  <p>I end up now having this query:</p>
  
  <pre><code>$post = Post::
          join('comments', 'comments.post_id' , '=', 'posts.id')
          -&gt;groupBy('posts.id')
          -&gt;orderBy(DB::raw('COUNT(posts.id)'))
          -&gt;paginate(6);
  </code></pre>
  
  <p>{{ $post->author }} works...
  but i cant get for example {{ $post->comment->count()}} from blade. In my previous query (above) it works. dunno why.</p>