838 0 0 0
Last Updated : 2025-04-28 22:07:32
Sometimes, You will need to order by a varchar column as an integer. for example if you have the billNumbers in two rows as 5 and 1400 the order as varchar in desc order will get that with 5 first then that with 1400. While the opposite is what is wanted in the ordering using integers.
//orderByRaw('CONVERT(billNumber, SIGNED) desc')
$lastBillNumber = ProvincialBill::where('assembly', $element['province'])->orderByRaw('CONVERT(billNumber, SIGNED) desc')->first() ;
return $query->orderByRaw('CAST(billNumberAS DECIMAL)' desc);