Modify label in select options
id like to change the title attribute, i currently have it like this (song name):
but id like to show the artist too:
but idk how to do it hmmm
Solution:Jump to solution
final code:
```php
Forms\Components\Select::make('song_id')
->searchable()
->relationship(name: 'song', titleAttribute: 'name')...
15 Replies
Try reading the documentation here: https://filamentphp.com/docs/3.x/forms/fields/select#customizing-the-relationship-option-labels
if i make it searchable doesnt work
i need to make it searchable
example when it works:
example when it doesnt:
how to make it searchable but it also shows the full song name with the artist?
also tried:
->searchable(['song.name', 'artists.name'])
doesnt workLooks like it should work. Does searchable work for that second example if you remove the custom option labels?
Should the search also return hits for the artist name?
If for whatever reason it doesn’t work you could also try without a relation and just use getSearchResultsUsing.
"Does searchable work for that second example if you remove the custom option labels?"
yes
the idea for now is search by song name
The example in the docs has searchable after the relationship and getOptionLabel…
Did you try that (it shouldn’t matter and I don’t have access to the code to check right now but who knows).
yeah already tried it
same result
seems im not missing anything
but idk
So if you try this example from the docs and leave out the artist for now, does that work?
Just return the song title
i think i have it
before:
->relationship(name: 'song')
now:
->relationship(name: 'song', titleAttribute: 'name')
let me double checkSolution
final code:
like this works fine
That would make sense because it won’t know what column to search without it
It has a default I think, but that might be ‘name’.
Or actually ‘title’
Glad it works now
yeah i see, yeah it may
(:
thanks for ur time bro
avicii was named tim too xd
just if u wanna have a look - https://discord.com/channels/883083792112300104/1199422071776755853 🙌 🙌 🙌 😛