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
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')
$query->orderByRaw("section::int", "desc")->get();
© 2022 - 2024 — McMap. All rights reserved.