Benjacho / belongs-to-many-field-nova

Belongs To Many field Laravel nova to represent many to many relationship in field.
MIT License
157 stars 81 forks source link

Resources always sorted by "name" - even when using "optionsLabel" #34

Closed Athlon1600 closed 4 years ago

Athlon1600 commented 4 years ago

This should be a super easy issue to fix.

Basically my database model does not have a name column, which is fine because I can just use optionsLabel function to specify keyword as the column that's to be used for the option titles.

Works great. image

Now if I wanted sort ^ that list alphabetically, I should be able to do that by overriding the relatableQuery method on my Keyword model like this: image

The problem is that the sort order gets completely overwritten by this piece of logic inside ResourceController.php here: https://github.com/Benjacho/belongs-to-many-field-nova/blob/master/src/Http/Controllers/ResourceController.php#L35

image

I don't have a name column, and even if I did, I would rather determine sort logic myself via relatableQuery as explained above. So the sorting just breaks because of this.

Two potential solutions here:

I decided to go with option 1.