I have here an eloquent query that retrieves purchases data. It has a relationship with tables (customer and cashier
) and was declared on their models. Right now, I'm trying to get data by created_at
in DESC
order but doesn't seem to work. Can anyone point me my mistake here?
$data = Purchases::with('customer', 'cashier')->where('balance', '>', 0)->orderBy('created_at', 'DESC')->get();
Any help is much appreciated.
CodePudding user response:
The syntax is correct and it should work.
Alternatively, you can use latest()
.
CodePudding user response:
It's working now. I just added order: [[ 0, "desc" ]]
on my datatables. See: https://datatables.net/examples/basic_init/table_sorting.html
It wasn't a query issue but a view issue.