here it is:-
$query = Section::orderBy("section", "desc")->get();
section here is a column with type string yet it is having numbers in it where i want to order by those numbers thanks for your response
you can use orderByRaw with mysql convert
$query = Section::orderByRaw('CONVERT(section, SIGNED) desc')->get();
First you should use proper data types while designing schema.
For your existing schema you can tweak your order by clause to type cast your value at runtime using orderByRaw method
->orderByRaw('section * 1 desc')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With