@PovilasKorop: My new quick 3-minute video on Filament Daily channel. PHP Enums in @filamentphp: Practical Example https://youtube.com…
Summary
This 3-minute video demonstrates how to use PHP enums in a Filament project to uniformly manage invoice statuses, color labels, and action visibility, avoiding hard-coded errors and achieving a single source of truth.
View Cached Full Text
Cached at: 07/24/26, 05:18 PM
My new quick 3-minute video on Filament Daily channel.
PHP Enums in @filamentphp: Practical Example https://t.co/mxiTfn5MFe https://t.co/ay6RUXIjIr
TL;DR: Use PHP enums in Filament projects to unify invoice statuses, status label colors, action visibility, and more — avoiding hardcoded string errors and achieving a single source of truth.
Using Enums in a Construction Management Project
This short video is an extension of the previously introduced construction management project, focusing on how to effectively leverage PHP enums in Filament. Taking invoice processing as an example, common actions include approving, sending, voiding, etc. — all based on the invoice’s current status. Enums clearly define all status options, eliminating the need for raw strings.
Defining the Enum and Model Casting
Create an InvoiceStatus enum class listing all possible statuses (e.g., Draft, Approved, Sent, Overdue, Paid, Void, etc.). Then, in the Invoice model, cast the status field to this enum:
protected $casts = [
'status' => InvoiceStatus::class,
];
This prepares the way for use in Filament.
Colors and Labels in the Filament Layer
Define hasColor() and hasLabel() methods in the enum that return the corresponding color and label based on the status value. For example, in an invoice table, a badge column will display different colors per status (e.g., “Paid” in green, “Overdue” in red). Once configured, Filament renders the badges automatically — no extra code needed.
Action Visibility and Status Transitions
Common actions in Filament forms (approve, void, send) should be visible only when the current status permits. Inside the enum class, define an allowedTransitions array that specifies which statuses can transition to which. For example:
- Draft status: can approve
- Approved status: can send, can also void (any status except Void itself can transition to Void)
Use a canTransitionTo() method to check whether the current status allows the target transition. Set the action button’s visibility condition to $record->status->canTransitionTo(InvoiceStatus::Void). The button will then only appear when a transition is valid.
More Complex Logic
The enum class can also encapsulate other business rules, such as “can accept payment” or “finance is locked”. These methods can be called directly in queued jobs or controllers, ensuring the same logic is used both inside and outside Filament — making the enum your “one-stop source of truth.”
Summary
PHP enums (introduced in PHP 8.0/8.1) are widely used in Filament to centrally manage status-related display, validation, and action visibility. This reduces string typo errors and improves code maintainability. If you need the full construction management system source code, you can join the Filament examples paid membership or purchase a single project for $9.
Source: https://www.youtube.com/watch?v=8DJpB0LMv8I
Similar Articles
@Easycompany333: Compiled 6 Claude Skills for video that you can try directly: 1. HyperFrames – generate animated video with one sentence. Articles, tweets, product intros can all become MP4. Suitable for product promotion, tutorial openers, short social videos. https://github.com/heyg…
Compiled 6 Claude Skills for video that can be used directly, covering auto-generated animated videos, AI-assisted rough cuts, React component rendered videos, multimedia generation toolbox, Chinese editing agent, and video prompt writing open-source tools.
@FinanceYF5: 这是这个视频里的幻灯片,如果你想自己看一遍的话: https://thariqs.github.io/cc-video-editing-deck/…
This presentation explains how Fable used Claude Code to edit its own launch video, providing a step-by-step guide with slides.
@WEB3_furture: This is the most concise and clearest demo of Claude Code I've ever seen. I specifically translated it into Simplified Chinese to share for learning. In just 7 minutes, you'll thoroughly understand 12 core concepts of Claude Code. Highly recommend taking some time to watch it—it's absolutely worth it!
A 7-minute tutorial video explaining 12 core concepts of Claude Code, translated into Simplified Chinese for educational purposes.
@Sixtimenight: https://x.com/Sixtimenight/status/2086079773793833216
Introducing a Jianying short-video mass-production workflow: use Codex to copy existing manually tuned templates, operate Jianying drafts via VectCutAPI and jianying-editor-skill, and replace one-by-one generation from scratch, enabling batch production and automated publishing.
@zhuolinnn: Today I continued using @leeoxiang's skill to produce a 50-second talking-head video. Thank you to the teacher for the ElevenLabs credits, and I also experienced a different picture-in-picture effect. Meanwhile, I'm sharing the joy of using Feishu CLI to schedule content creation for me. I think the value of this vtake-cut skill lies in enabling more people to express their ideas with zero barriers…
The author shares their experience of making a 50-second talking-head video using @leeoxiang's skill, ElevenLabs, and Feishu CLI, emphasizing that the vtake-cut skill allows more people to express their ideas with zero barriers.