F
Filamentβ€’10mo ago
pinoooh

Enum in TextEntry of InfoList

Hi, I have a model with an enum-property (cast) which I want to display in an infolist, but this gives me an Error:
TextEntry::make('model.enumProperty')
TextEntry::make('model.enumProperty')
this results in Object of class App\Enums\MyEnum could not be converted to string I don't mind converting the value e.g. using formatStateUsing on the TextEntry but the code already fails on the name. As a workaround I can do this, but this it's not very nice πŸ™‚
TextEntry::make('model.created_at')
->formatStateUsing(static function (Model $model): string {
...
}
}
TextEntry::make('model.created_at')
->formatStateUsing(static function (Model $model): string {
...
}
}
Any idea?
4 Replies
pinoooh
pinooohOPβ€’10mo ago
Didn't find a solution to this problem, but I have a "workaround": use a ViewEntry, then load a table in a new livewire component within the view. In the table I can use TextColumn which has support for the enum.
Blaze
Blazeβ€’9mo ago
->formatStateUsing(function (string $state) { return YourEnum::from($state); }), No problem
pinoooh
pinooohOPβ€’9mo ago
thanks for your reply but the state is already cast to an enum (by the model)
Sjoerd24
Sjoerd24β€’9mo ago
So you dont need to do anything right? With enums i add ->badge() almost always but should work out of the box ..? What is the error you get?
Want results from more Discord servers?
Add your server