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:
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?
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:
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?