© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•12mo ago•
11 replies
Dmitriy

TextColumn throwing an exception for the empty ENUM value

I have an attribute called
language
language
that is often used in several tables and for now 3 language codes could be used as values.

So, I created an Enum class
App\Enums\Language
App\Enums\Language
and in the Eloquent model the attribute
language
language
is cast correctly:
protected $casts = [
  'language' => App\Enums\Language::class,
];
protected $casts = [
  'language' => App\Enums\Language::class,
];


In the related Filament Resource I have a dropdown field for the form:
return $form
->schema([
  Filament\Forms\Components\Select::make('language')
    ->nullable()
    ->options(App\Enums\Language::class)
]);
return $form
->schema([
  Filament\Forms\Components\Select::make('language')
    ->nullable()
    ->options(App\Enums\Language::class)
]);


And a text column for the list table:
return $table
->columns([
  Filament\Tables\Columns\TextColumn::make('language')
    ->sortable()
    ->badge()
]);
return $table
->columns([
  Filament\Tables\Columns\TextColumn::make('language')
    ->sortable()
    ->badge()
]);


As the result, on the
Edit
Edit
and
Create
Create
pages the dropdown shows available labels from the Enum class and everything works as it should.

But the problem that some of the existing records don't have a value for the attribute
language
language
.

And as the result, on the
List
List
page an exception is throwing with the message
"" is not a valid backing value for enum App\Enums\Language
"" is not a valid backing value for enum App\Enums\Language
.

I found a lot of related articles but still wasn't able to fix it. For example this one https://www.answeroverflow.com/m/1184219387109068871

Here https://medium.com/@yihen_26052/the-magic-from-method-of-enum-in-php-8-1-ad5a1a8f9298 also there is a good explanation between Enum
::from()
::from()
and
::tryFrom()
::tryFrom()
methods.

It seems that method
tryFrom
tryFrom
returns
null
null
for invalid values instead of throwing an exception. Maybe this could be a good fix for such case and could be fixed in the upcoming Filament version?

Or probably there is some workaround to avoid the error?
I would also be grateful if you could suggest what else could be used to move the repeating code into one place.

I know about the option of creating a separate table for languages ​​in the database and linking it to the existing records. But for now I would like to put the list of languages in some PHP class.
Nullable PHP Enum in Table TextColumn Oddity - Filament
I have a model/table that is a collection of various statuses (PHP Enum values) that are nullable if it's never been set.

When using a TextColumn like so:

Tables\Columns\TextColumn::make('state.current_confirmation_status')
  ->label('Confirmation')
  ->placeholder('Unknown')
  ->badge()
  ->sortable(),
Tables\Columns\TextColumn::make('state.current_confirmation_status')
  ->label('Confirmation')
  ->placeholder('Unknown')
  ->badge()
  ->sortable(),


If the field actually has an...
Nullable PHP Enum in Table TextColumn Oddity - Filament
Medium
The Magic “from” method of Enum in PHP 8.1
In PHP 8.1, the enums i.e enumerations are introduced as a language feature. The feature comes with a few built in methods and one of the…
The Magic “from” method of Enum in PHP 8.1
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

TextColumn placeholder empty
FilamentFFilament / ❓┊help
3y ago
Enum trait in TextColumn
FilamentFFilament / ❓┊help
3y ago
How to display an enum's label rather than value in a TextColumn?
FilamentFFilament / ❓┊help
3y ago
TextColumn with subquery value
FilamentFFilament / ❓┊help
3y ago