Hello everyone, I have a question regarding the smartest use of sortBy(). I’m trying to sort a Pages Collection by the value of a specific field (say the fields name is ranking).
$sorted_children = $page->children()->sortBy('ranking', 'desc')
So far, so easy. On some pages though, the ranking field has different values for my two languages. I always want to sort the Pages Collection by the value of the field in English and ignore the German value.
As far as I understand it, the sortBy() function does not have an option to query the value for a different language than the currently set one. Is that right?
Ideally I would like a solution that looks something like this
// sort by the english value of ranking field
$sorted_children = $page->children()->sortBy($lang='en', 'ranking', 'desc')
The only way I see right now would work like this
$sorted_children = $page->children()->sortBy(function ($page) {
return $page->content('en')->ranking();
}, 'desc');
This would add quite a lot of code though and I’m wondering if there’s a more elegant solution.