How to display an enum's label rather than value in a TextColumn?
My
Customer
model has a priority
column which stores any one of these values: 1, 2, 3.
How do I make TextColumn::make('priority')
display the value instead of the key?
Here's what I have. However I don't want this displayed as a description but rather as the value itself.
9 Replies
move to enums instead of const
Solution
Found the solution.
->formatStateUsing()
I'm starting to use Enums less and less lately. I haven't found a straight forward way of fetching labels or a random item when working with Enums without defining Traits.
if you would use enum you could just pass it in the
options()
for the color there's also a method
I hadn't realized Filament ships with a
HasLabel
interface! Been using my own HasLabel
trait this whole time. Got to refactor a dozen projects now lolrtfm lol
š
RTFM will be my epitaph šŖ¦ lol
Thanks again mate
Ok refactored my code to use an enum instead. Got it working in the Form.
But what about in the Table in the TextColumn?
never mind, forgot to cast my enum in my Eloquent model. Sorted. Thanks