How to modify options label on the attach action select.
Hey, I'm building this app in which within a Relation Manager I want to attach a
gameday
, which is basically just a date (e.g. 2023-08-24
), but I wish to modify the option labels to make it more readable (e.g. Sunday, Aug 13, 2024
. I attempted this:
But the labels didn't change at all. I even tried a dd($record->date)
inside of the getOptionLabelFromRecordUsing()
callback, but nothing died or dumped. So it appears that the method isn't being called at all. Certain methods (e.g. multiple()
) worked as intended when called on the select, but others (e.g. getOptionLabelUsing(//)
or getOptionLabelFromRecordUsing(//)
didn't seem to have any effect.
Am I going about this the wrong way? Is there a better way to do this? Is there an error in my code? Or did I stumble across a bug?Solution:Jump to solution
Maybe I'm misunderstanding what you are trying to do, but if you want to change the option labels on the attach dropdown, it'd be ...
```php
Tables\Actions\AttachAction::make()
->recordTitle(function ($record) {...
6 Replies
Solution
Maybe I'm misunderstanding what you are trying to do, but if you want to change the option labels on the attach dropdown, it'd be ...
Assuming the attribute is cast to a date. Obviously modify the format to suit.
That would do it, I now found it in the docs, not sure why I didn't find it earlier. Thanks!
Note that this may make searches a little non intuitive.
sure, as well as the ordering...
I seem to recall running in to this before, that there isn't a way to modify the search query, only provide an array of additional fields to search. So one of my app examples is ...
... which works fine, as the search is on the un-modified pair of fields. But when completely changing the format of the displayed record attribute, I don't think there's a way of fully customizing the search query. I may be wrong, there may be, but I remember not being able to find it.
Yeah, you can modify the query in general, but as far as I'm aware, there is no way to inject a search instance into a callback.