You may try using the COLLATE keyword (at least that's for MySQL, not sure for the other DB engines).
Something like this should work: ->orderBy('last_name', 'ASC COLLATE latin1_german2_ci')
Ref: official MySQL docs
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hello everyone, I have a problem that I suppose has a really easy and obvious answer that I can't figure right now.
Right now I'm using the simplest of simplest queries to populate a select list.
My problem is that when I use ->sortBy('last_name') the majority of names appear in the right order, but two of them that start with "Á" appear at the end of the list.
It's there something that I should add? There is no need of the 'Desc' part since the rest of "A" last names appear at the start.
Thanks for your time.
@andonovn It looks like a problem from the sortBy method used on a collection and not the orderBy method used on a query.
I don't think sortBy support UTF-8 characters by default, which is the issue here. I've found this solution on stackoverflow:
setlocale(LC_COLLATE, 'fr_FR.utf8'); // No need to set this if you're doing it elsewhere
$collection->sortBy("name", SORT_LOCALE_STRING); // Signals to arsort() to take locale into consideration
https://stackoverflow.com/questions/39374842/laravel-5-3-collection-sort-utf8-strings
Another solution might be to change your query if that's a possibility. MySQL handles sorting pretty well and it will take off a bit of the complexity from your controller/view.
Please or to participate in this conversation.