That's strange that you obtain two different results (about the order) with the same controller.
You have necessarily something that reorder your results.
Can you explain and show the differences and in which precise conditions ?
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi all,
I don't know how to solve this, but in general, I have this chunk of code
$tournaments = Tournament::select('name', 'city', 'date', \DB::raw(sprintf(
'(6371 * acos(cos(radians(%1$.7f)) * cos(radians(latitude)) * cos(radians(longitude) - radians(%2$.7f)) + sin(radians(%1$.7f)) * sin(radians(latitude)))) AS distance',
$latitude,
$longitude
)))
->having('distance', '<', request('distance') ?? self::DEFAULT_DISTANCE)
->orderBy('distance', 'asc')
->get()
->groupBy('city');
return $tournaments;
Which returns grouped cities, but the problem is when I try to get this endpoint directly it gives me sorted data like this
{
"Cakovec": [
{ "distance": 12.906106587461018, },
{ "distance": 12.906106587461018,}
],
"Novi Marof": [
{ "distance": 16.303102724639714,}
],
"Sv Martin": [
{ "distance": 23.9061609409841,}
],
"Split": [
{"distance": 311.2904383884394,}
]
}
Which is fine, because I'm sorting this first by distance and then grouping by city, but the problem is when I try to fetch the data with http request, then 'Split' is not the last result even tough this city should be the last because of distance. Seems like browser/js or something is sorting groupby alphabetically...
Any ideas?
I found a workaround, this is common issue, here how you can keep sorting in Angular
https://github.com/angular/angular/issues/31420#issuecomment-530561112
I just removed asIsOrder props, and index because I don't need it. It seems like working now
Please or to participate in this conversation.