@geerizzle I think it could be
$items = $items->sortBy(function ($item) {
return str_replace("'", '', $item->yourField);
});
Just replace yourField with your property.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I want to sort data from my model in alphabetical order, but ignoring an apostrophe if it's at the start:
e.g. Alan 'Bob' Clare currently puts Bob at the start. How can I modify my query or sort on the collection to ignore apostrophes?
I thought this would work but it doesn't:
$items= $items->sortBy(function ($item) {return str_replace(''', '', $i['item']);});
ORDER BY TRIM(BOTH "'" FROM yourfield)
If that doesn't work use the actual ascii for apostrophe.
Please or to participate in this conversation.