title: Laravel MySQL orderBy count
body: <p>I'm using Laravel and MySQL, and I have a table <em>post</em> that represents post where users can comment on it, now I wanna order posts by the number of comments of each post in ascending/descending order, how do I do this in Laravel? I don't want to add a field in <em>post</em> table to keep track of the number of comments of each post, because updating that field manually each time a comment or a comment's comment is added/deleted drives me crazy...</p>
  
  <p>This is how I create my <em>posts</em> table and <em>comments</em> table:</p>
  
  <pre><code>Schema::create('posts', function($table) {
      $table-&gt;increments('id');
      $table-&gt;string('title', 100)-&gt;unique();
      $table-&gt;string('content', 2000);
      $table-&gt;timestamps();
  });
  Schema::create('comments', function($table) {
      $table-&gt;increments('id');
      $table-&gt;string('content', 2000);
      $table-&gt;unsignedInteger('post_id');
      $table-&gt;foreign('post_id')-&gt;references('id')-&gt;on('posts')-&gt;onDelete('cascade')-&gt;onUpdate('cascade');
      $table-&gt;unsignedInteger('parent_id')-&gt;nullable();
      $table-&gt;foreign('parent_id')-&gt;references('id')-&gt;on('comments')-&gt;onDelete('cascade')-&gt;onUpdate('cascade');
      $table-&gt;timestamps();
  });
  </code></pre>
  
  <p>And this is how I setup relationship between posts and comments in my Post model:</p>
  
  <pre><code>public function comments() {
      return $this-&gt;hasMany('Comment', 'post_id');
  }
  </code></pre>
  
  <p>And in Comment model:</p>
  
  <pre><code>public function post() {
      return $this-&gt;belongsTo('Post', 'post_id');
  }
  </code></pre>