Select relationship orderBy is without function
Package
filament/forms
Package Version
v2.0.0
Laravel Version
all
Livewire Version
all
PHP Version
all
Problem description
Select field orders items by $displayTitleColumn. But as the primary key is usually an integer, the order gets lost when returning the JSON.
For example:
Route::get('/test', fn () => [
2 => 'N2',
1 => 'N1',
]);
will result in:
{
"1": "N1",
"2": "N2"
}
We would need to wrap every result in an array to prevent this.
Expected behavior
Correctly ordered results.
Steps to reproduce
Select::make()->relationship()
Reproduction repository
No response
Relevant log output
No response
I guess this is a js specific notion, see https://www.stefanjudis.com/today-i-learned/property-order-is-predictable-in-javascript-objects-since-es2015/, and ideas here https://stackoverflow.com/questions/69946683/can-i-preserve-the-order-of-a-javascript-objects-entries-when-some-entry-keys
So dan mentioned could prefix all the IDs and then strip that back in the mutate before save. lets maybe document that workaround here until we have a full solution? I will see what i can throw together if someone else doesn't beat me to it.