© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•3y ago•
31 replies
Samus_Aran

Enum cast not working when editing a resource

I have a model "Article" with a "category" field. This Field is being cast to an enum ArticleCategory::class. The Enum class is implementing Filament\Support\Contracts\HasLabel.

In my ArticleResource form I am populating a select input using ->options(ArticleCategory::class). I am also providing ->default(ArticleCategory::STORY) to set the default during article creation. Further down in my form I have a conditional grid, which only gets displayed, if $get('category') matches ArticleCategory::REVIEW

Everything works when creating a new article. During editing however, I noticed that my conditional grid is never displayed. Upon further inspection I found out that the value for "category" was not an instance of my Enum class, but just a plain String.

I was able to fix my issue using this piece of Code in my EditArticle.php file:

protected function mutateFormDataBeforeFill(array $data): array
{
    $data['category'] = ArticleCategory::from($data['category']);
     
    return $data;
}
protected function mutateFormDataBeforeFill(array $data): array
{
    $data['category'] = ArticleCategory::from($data['category']);
     
    return $data;
}


This feels rather cumbersome, as I was expecting that Filament would take my Enum Cast into account during editing, considering that the Select Input works so nicely with Enum classes.

Is this a bug? Or is there a simpler way to do this? Or is this already the proper way to do this?
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Enum is cast when creating but not editing
FilamentFFilament / ❓┊help
12mo ago
Saving related items when editing/creating a resource
FilamentFFilament / ❓┊help
3y ago
Missing route parameter when editing resource
FilamentFFilament / ❓┊help
3y ago
Modal resource editing
FilamentFFilament / ❓┊help
2y ago