$posts = Post::with('comments')
->join('comments', 'comments.post_id', '=', 'posts.id')
->select('posts.*', 'comments.*')
->groupBy('posts.id')
->orderBy(DB::raw('COUNT(`posts`.`id`)'), 'asc')
->paginate(10);