is there a formatStateUsing for IconColumn?
What I have:
I have a table with a one-to-many boolean icon column (positionData.is_active)
Currently the State is populates with all the records for example (true, false, true)
What I want to do:
I just want a single value returned.
What I have tried
If it was a TextColumn I could use something like
But this doesnt seem to be a thing for IconColumns.
I've tried using the
But the format and size is totally different than the Icon Columns. Any suggestions?
But the format and size is totally different than the Icon Columns. Any suggestions?
Solution:Jump to solution
```php
Tables\Columns\IconColumn::make('position_data_active')
->boolean()
->state(fn (YourModel $record): bool => $record
->positionData...
5 Replies
Do you mean withing the TextColumn->formatStateUsing() ?
I can, but the TexColumns dont seem to render icons the same as IconColumns See attached.
If I use the IconColumn, I cant seem to filter out one of the one to many icons (Does that make sense?) See attached.
@403gtfo haven't tried it in Filament but maybe you should use oneOfMany instead of oneToMany? Like latestOfMany and similar? Then you would get one record from Eloquent: https://laravel.com/docs/11.x/eloquent-relationships#has-one-of-many
Laravel - The PHP Framework For Web Artisans
Laravel is a PHP web application framework with expressive, elegant syntax. We’ve already laid the foundation — freeing you to create without sweating the small things.
Solution
?
As always you set me off on the right path 😄
I couldnt get the morph to work (I'll have to go watch your videos on it again to better wrap my head around it.) But I did just make another basic relation.
Then in the filament table I can just use:
Works like a charm! Thanks again. Love your work & videos.
😮 that is handy to know, thanks man! Added yours as the solution to the question I asked. But found I could do a simple extra model relation and it worked even better then modifying the state.