title: Laravel sortBy paginate
body: <p>I have a <em>posts</em> table and <em>comments</em> table, comment belongs to post, and I have the relationship setup in Post and Comment model. I did sort posts by the number of comments of each post like this:</p>
  
  <pre><code>      $posts = Post::with('comments')-&gt;get()-&gt;sortBy(function($post) {
             return $post-&gt;comments-&gt;count();
        });
  </code></pre>
  
  <p>What I wonder is how I can paginate these sorted posts? </p>
  
  <pre><code>      $posts = Post::with('comments')-&gt;get()-&gt;sortBy(function($post) {
             return $post-&gt;comments-&gt;count();
        })-&gt;paginate(20);
  </code></pre>
  
  <p>doesn't work and gives me error that says paginate is an undefined method.</p>