irsyadadl's avatar

Can't use pagination before shortBy

I have project call forum site, I wanna short them by popular with comment count.

$topics = Topic::latest()
->withCount('topics')
->paginate(12)
->sortByDesc('topics_count');

The problem is, I can't use pagination on it, when I tried to use $topics->links(), it said if the link method was not founded. So guys. How I can do this while I need to make sure if this have a pagination. Thanks.

0 likes
1 reply
tisuchi's avatar

Just use orderBy instead of sortBy-

$topics = Topic::latest()
->withCount('topics')
->orderBy('topics_count', 'desc')
->paginate(12);
1 like

Please or to participate in this conversation.