Laravel 5: Is there a non-case sensitive way to sort a collection by an attribute?
sortBy()
second argument allows you to set some flags regarding on how the sorting should be handled.
Flags are exactly the same as PHP sort()
native function.
- SORT_REGULAR - compare items normally (don't change types)
- SORT_NUMERIC - compare items numerically
- SORT_STRING - compare items as strings
- SORT_LOCALE_STRING - compare items as strings, based on the current locale. It uses the locale, which can be changed using setlocale()
- SORT_NATURAL - compare items as strings using "natural ordering" like natsort()
- SORT_FLAG_CASE - can be combined (bitwise OR) with SORT_STRING or SORT_NATURAL to sort strings case-insensitively
source: php.net
You could try by using $collection->sortBy('key', SORT_NATURAL|SORT_FLAG_CASE)
.