You are using an alphanumerical sort, you need to use a natural sort.
What is the column type for price?
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I make query orderby from lower value to greater value. Although I orderBy ASC this is not get as require
Price Amount Total
1 4 3
10 4 3
2 2 1
5 2 1
5 4 3
9 4 3
I think it need to adjust in double or triple digit when 1, 2, 3, 4, 5, / it make correct ascending but when two digit enter , cannot ascending order.
1 4 3
10 4 3
13 4 3
2 2 1
5 2 1
5 4 3
6 4 3
7 4 3
8 4 3
9 4 3
how can I fix this
public function buyshow(){
$buydata = Buy :: orderBy ('price','ASC')->get();
return response()->json([
'buydata' => $buydata,
]);
}
What is the type of the price column - it is sorting like a VARCHAR or TEXT column type?
You can cast the value as INT in a raw statement, but better to have the appropriate type in the first instance!
Untested, but this should work:
$buydata = Buy::orderByRaw('CAST(price AS UNSIGNED) ASC')->get();
Please or to participate in this conversation.