php - Why is data that i've sorted in a laravel controller, not displaying as sorted on the view

I have 3 related tables and I want to sort the data by programme_title which is in the programmes table. This method in my controller works and I can dump the new array sorted by programme_title.

However, when I print this in my view (vue.js), the array is sorted by default, id again. Any reason for this?

return Inertia::render('Applications/Edit', [
    $programmes = AppProgrammes::with(['programmeInstances', 'programmes'])
        ->get()
        ->sortBy(function($programmes) { 
            return $programmes->programmes->programme_title;
        }),
    'programmes' => $programmes,
]);

Answer

Solution:

This happened once to me, the "issue" is that when you get the final result in javascript, surely it is a JSON, and it is automatically sorted by index (by javascript, that is the unchangeable behavior of Javascript related to JSON), you cannot have a "custom sort"... so you will have to find another solution for this...

I know it is really frustrating, but it is the only way...

If you dump your result, I think I could try to help you more.

Source