'How to properly order the collection 'asc'
Im trying to order 'asc' the collection below but its not working with the sortBy collection method. Do you know how to properly achieve that?
$topCategories = PostCategory::pluck('category_name', 'category_icon')->toArray();
$topCategories = collect($postInformation['categories']['data'])->map(function ($postCategory) {
return
$postCategory['name']['en'];
})->sortBy('category_name')->toArray();
dd($topCategories) shows like:
^ array:12 [▼
0 => "Testing category"
1 => "category 2"
...
]
But the category 2 should appear first.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
