Reputation: 43
I have a column which shows the number of total referrals a user have.
Below is my code. I want to paginate order by the person have highest number of refs. I tried with max('totalref')
but then paginate
not works.
So I am confused with this type of alignment
public function leaders()
{
$accounts = Account::Where('totalref','>' , 5)->orderBy('id','ASC')->paginate(200);
return view('admin.leaders', compact('accounts'));
}
Upvotes: 1
Views: 54
Reputation: 18916
When you are working with paginated data, you want to do ordering, searching and etc. in the query. As based on your comment, it seems like totalref is a string in your database, convert it to an integer and the following will work.
$accounts = Account::Where('totalref','>' , 5)->orderBy('totalref','desc')->paginate(200);
Upvotes: 1