Level 50
Jul 22, 2023
1
Level 5
How to sort by multi columns with cursorPaginate
I have this code:
$products = OrderProduct::query()
->with([
'product' => function ($query) {
$query->select('id', 'title', 'price');
},
'order' => function ($query) {
$query->paid();
}
])
->selectRaw('
product_id,
SUM(quantity) as quantity_sold,
SUM(price * quantity) as total_sales
')
->groupBy('product_id')
->orderByDesc('product_id')
->cursorPaginate();
How to sort by total_sales desc with cursor paginate, i put total_sales instead of product_id the first page is working when I press next I got this error
Unable to find parameter [total_sales] in pagination item.
Please or to participate in this conversation.