Introduction
Enums are special PHP classes that represent a fixed set of constants. They are useful for modeling concepts that have a limited number of possible values, like days of the week, months in a year, or the suits in a deck of cards. Since enum “cases” are instances of the enum class, adding interfaces to enums proves to be very useful. Filament provides a collection of interfaces that you can add to enums, which enhance your experience when working with them.Enum labels
TheHasLabel interface transforms an enum instance into a textual label. This is useful for displaying human-readable enum values in your UI.
Using the enum label with form field options
TheHasLabel interface can be used to generate an array of options from an enum, where the enum’s value is the key and the enum’s label is the value. This applies to form fields like Select and CheckboxList, as well as the Table Builder’s SelectColumn and SelectFilter:
Status::class is the enum class which implements HasLabel, and the options are generated from that:
Using the enum label with a text column in your table
If you use aTextColumn with the Table Builder, and it is cast to an enum in your Eloquent model, Filament will automatically use the HasLabel interface to display the enum’s label instead of its raw value.
Using the enum label as a group title in your table
If you use a grouping with the Table Builder, and it is cast to an enum in your Eloquent model, Filament will automatically use theHasLabel interface to display the enum’s label instead of its raw value. The label will be displayed as the title of each group.
Using the enum label with a text entry in your infolist
If you use aTextEntry in an infolist, and it is cast to an enum in your Eloquent model, Filament will automatically use the HasLabel interface to display the enum’s label instead of its raw value.
Enum colors
TheHasColor interface transforms an enum instance into a color. This is useful for displaying colored enum values in your UI.
Using the enum color with a text column in your table
If you use aTextColumn with the Table Builder, and it is cast to an enum in your Eloquent model, Filament will automatically use the HasColor interface to display the enum label in its color. This works best if you use the badge() method on the column.
Using the enum color with a text entry in your infolist
If you use aTextEntry in an infolist, and it is cast to an enum in your Eloquent model, Filament will automatically use the HasColor interface to display the enum label in its color. This works best if you use the badge() method on the entry.
Using the enum color with a toggle buttons field in your form
If you use aToggleButtons form field, and it is set to use an enum for its options, Filament will automatically use the HasColor interface to display the enum label in its color.
Enum icons
TheHasIcon interface transforms an enum instance into an icon. This is useful for displaying icons alongside enum values in your UI.
Using the enum icon with a text column in your table
If you use aTextColumn with the Table Builder, and it is cast to an enum in your Eloquent model, Filament will automatically use the HasIcon interface to display the enum’s icon aside its label. This works best if you use the badge() method on the column.
Using the enum icon with a text entry in your infolist
If you use aTextEntry in an infolist, and it is cast to an enum in your Eloquent model, Filament will automatically use the HasIcon interface to display the enum’s icon aside its label. This works best if you use the badge() method on the entry.
Using the enum icon with a toggle buttons field in your form
If you use aToggleButtons form field, and it is set to use an enum for its options, Filament will automatically use the HasIcon interface to display the enum’s icon aside its label.
Enum descriptions
TheHasDescription interface transforms an enum instance into a textual description, often displayed under its label. This is useful for displaying human-friendly descriptions in your UI.
Using the enum description with form field descriptions
TheHasDescription interface can be used to generate an array of descriptions from an enum, where the enum’s value is the key and the enum’s description is the value. This applies to form fields like Radio and CheckboxList: