I am looking for a way to sort the collection in such a way that name values starting with the alphabet comes at the top and then name values that start with numbers. For example:
$collection = collect([
['name' => 'b', 'symbol' => '#'],
['name' => '2a', 'symbol' => '$'],
['name' => '1', 'symbol' => '@'],
['name' => 'a', 'symbol' => '%']
]);
The above collection should be sorted like this:
[
[
"name" => "a",
"symbol" => "%",
],
[
"name" => "b",
"symbol" => "#",
],
[
"name" => "1",
"symbol" => "@",
],
[
"name" => "2a",
"symbol" => "$",
],
]
But this is what I get when I sort it using sortBy
method:
$collection->sortBy('name')->values()->all();
[
[
"name" => "1",
"symbol" => "@",
],
[
"name" => "2a",
"symbol" => "$",
],
[
"name" => "a",
"symbol" => "%",
],
[
"name" => "b",
"symbol" => "#",
],
]
Any idea how to sort this collection so that names starting with letters come first?