Reuse Enums Across Your Laravel/Filament App (Stop Repeating Yourself)

Laravel Daily| 00:08:22|Mar 5, 2026
Chapters9
Overview of using PHP enums in Laravel and Filament and the idea of expanding a simple example.

Reuse PHP enums across Laravel and Filament to centralize logic, reduce typos, and enable automatic UI hints and filters.

Summary

Laravel Daily’s video by the creator demonstrates how PHP enums can serve as a single source of truth for status logic across an entire Laravel and Filament application. The presenter walks through an order status enum packed with color, icon, label, and description data, then shows how Eloquent casts, Filament forms and tables, filters, and widgets can all consume the same enum. He emphasizes that the enum becomes the ground-truth for business logic like isFinal or description, so changing text or behavior happens in one place and propagates everywhere. The video includes concrete examples: using an enum in an Eloquent scope for status queries, rendering a badge in Filament tables via the enum’s color/icon/label, and driving Filament filters with enum-provided descriptions. There’s also a note on using enum-based defaults in migrations, factories, and even public blade pages, plus a snippet on a Filament-specific static analysis tool (Filament Check) that enforces enum usage. By the end, the idea is clear: define the logic once, reuse it everywhere, and gain reliability and IDE-assisted accuracy. Filament Daily promises more checks in their Filament Check package, with a pro version offering additional rules.

Key Takeaways

  • Define the status logic once in a PHP enum and reuse it in Eloquent, Filament forms, filters, and views.
  • Filament automatically reads enum color, icon, label, and description to render badges, options, and radio filters without duplicating data.
  • Changing a label or description in the enum immediately updates all UI components and filters without editing Filament code.
  • Use enum casts in Eloquent models to enable IDE autocompletion and prevent typos compared to string literals.
  • Implement enum-based scopes in Eloquent to keep query logic readable and type-safe.
  • Defaults in migrations and factory states can be driven by enums to ensure consistency across environments.
  • Filament Check can enforce enum usage and guide future refactors or AI-generated changes.

Who Is This For?

Laravel developers building apps with Filament who want to consolidate business-logic into a single enum source of truth, improving reliability and reducing duplicate UI text. This is especially helpful for teams aiming to leverage Eloquent casts, Filament components, and database seeds with consistent enum-driven values.

Notable Quotes

"The enum should be the logic of possible options including stuff like color icon label for filament also description"
Intro clarifying what the enum contains and why it’s powerful.
"This is the source of truth of all the logic of that enum values the proof of single responsibility principle"
Emphasizes the single-responsibility aspect of enums for centralized logic.
"Filament automatically knows that this status is with this icon, with this label, and with this color"
Shows how Filament consumes enum metadata in UI elements.
"You change that in the enum and then it is automatically picked up"
Highlights the effortless propagation of changes from enum to UI.
"If you want to try it out these and other checks in your filament projects fill a check package"
Mentions the Filament Check tool and its availability/variants.

Questions This Video Answers

  • How can PHP enums improve consistency across Laravel apps with Filament?
  • Can I use a single enum to drive Eloquent casts, Filament UI, and database defaults?
  • What is the Filament Check package and how does it enforce enum usage?
LaravelPHP EnumsFilamentEloquent CastsEloquent ScopesFilament TablesFilament FiltersBlade/ViewsDatabase MigrationsFactories
Full Transcript
Hello guys, in this video I want to talk about PHP enums in Laravel and filament project and show you the example of how powerful it is if you reuse it in multiple places in whole of the project. So this tweet recently went pretty popular with 81 likes. So I decided to expand it with even bigger example. So imagine you have this enum order status with quite a few of functions and functionalities inside of the same enum and that's the whole point. The enum should be the logic of possible options including stuff like color icon label for filament also description also internal functions and then it's very powerful. Enum can be a great proof of so-called single responsibility principle where you have all the logic of all the options here in one file and if you need to change something you change it here and then this is scattered all over the project without any changes or minimal changes. So let me show you where such enum can be used in various places of the same project to be more powerful. So first let's start with eloquent. Imagine you have order status with these values. Let's not look at other parts of this enum. And then in the model of order you have casts and one of the casts is order status enum. And then what it allows you to do for example in the controller or wherever order is created we can have this. So autocomplete of order status something something which is autocompleted by IDE and you can choose the cases and avoid any typos which you may have done if you added just string value and to be honest many developers stop with just this behavior eloquent cast and then saving the enum values but we can show much more here. So imagine we have orders table in filament and also orders form and we can reuse that with filament functionality to have status like this. Not only the color and the label but also available potential options. So as you can see we have has color has icon and has label which also have the values for color icon and label respectively. Yep, this is the label. And then in the orders table of filament in the column, we just show status with badge. And then filament automatically knows that this status is with this icon, with this label, and with this color. Next, we can use filter with options of order status. And those options will be not just the names of the values. So we can have filter with radio buttons. And as you can see the filter contains the description. So where that description comes from you saw that in the enum we have has description which is automatically used by filament in the radio options. So has description here then get description here and then you have additional text with clarification of the value and if you want to change that text you don't need to change that in filament. You change that in the enum and then it is automatically picked up. So for example let's make any change of for example get label let's leave it as pending and then if we refresh here we should have pending changed here and in the filter and basically anywhere you use that enum just like that again this is the source of truth of all the logic of that enum values the proof of single responsibility principle and also in the same table you may see record actions approve or cancel and those are visible with the condition and condition is record status is final. That status is an enum. It's cast to enum and is final is within the same enum we have is final. Again the logic is in the enum and then wherever that logic fits in in the controller in filament wherever we just call is final and then the enum takes care of what that is final actually means. But those has label has icon and has color and everything is not just for filament. You can use it outside of filament. So for example there's a public page of confirmation of the order order confirmed. This is the blade and here we can find if we scroll down after the order details we should see this one order status get label. So you can call that function directly even outside of filament. Also in filament there's a view page for each order. And again here we have status with the badge with the label with the icon and if it is cancelled there is nothing to do about this order but if we go to anything that is in transition we have approve and cancel buttons which are visible again with the condition. So if we open that view order page of filament again we have action make approve and action make cancel and what do you know we have visible record status is final. And of course I'm even skipping to mention that everywhere that order status is appropriate it is used with enum with values instead of string values like cancelled because for example if someone gets cancelled it may have type or for example someone may do something like this and then you have a real bug. So that's why using enum values is better just for validation and for reliability. But even that is not all. There are a few more places where we can use that enum for example in eloquent scopes. So scope with status and that enum may be the parameter of that scope and then you can use that scope for example like this wherever you do eloquent queries again to avoid any typos. This is also pretty readable from human perspective or for example in filament there's one file for widgets with states I mean with stats similar words funny enough I'm not an English native speaker so stats status and states anyway get stats and then status is used multiple times again with scope also even in migration if you have the default value for that enum column we can do something like this so assign the default default again not with string value which may be not bulletproof not errorproof you can use enum as well here and also in the database factories for example in a definition you may use something like this but that may come default from migration but you can also use factory states and then use enums for different values here as well. So yes see how many usages there are for enums if you define the logic once and then reuse it all over your project. And finally in this video I want to show you how we implemented enum check inside of filament package fillet check that we use for like static analysis especially after AI generated code. So when I run vendor bin filler check on that project I intentionally left a few hiccups here and there. So for example it checks for string icons in favor of hero icon enums which appeared in filament in filament 4 from what I remember. So for example, if it detects the icon with that string instead of the enum, it flags that it should be hero icon outline check circle instead. And also another check that we have if we have enum detected without filament interfaces in the filament project, we suggest that it should have has label. So for example, there's payment method enum in this project without any filament. It's very simple one but maybe in the future you would want to use that in the filament table. So has label will be useful in the future or even now or even in general outside of filament to transform that enum into human friendly language. So yeah if you want to try it out these and other checks in your filament projects fill a check package there are 14 free rules and there will be more and there's also pro version with more rules and I will link that in the description below. So yeah, that's enum project based on the original tweet but expanded with more examples to showcase you the power of PHP enums if you use them all over the project. That's it for this time and see you guys in other

Get daily recaps from
Laravel Daily

AI-powered summaries delivered to your inbox. Save hours every week while staying fully informed.