0082-laravel-state-machines
CommunityImplement safe, validated state transitions in Laravel.
Software Engineering#workflow#laravel#state machine#domain events#transition validation#order lifecycle#spatie model states
AuthorMrJmpl3
Version1.0.0
Installs0
System Documentation
What problem does it solve?
It solves the problem of managing complex Laravel model status flows where each transition needs validation and side effects, avoiding brittle if/else logic and inconsistent state changes.
Core Features & Use Cases
- Type-safe state machines with Spatie Model States: Define states as classes and model the allowed transitions explicitly.
- Transition classes with validation and side effects: Encapsulate rules, timestamps updates, and event dispatching inside dedicated transition handlers.
- Clean model APIs for transitioning and guarding: Use
markAs*methods to trigger transitions andcanBe*methods to check whether a transition is allowed. - Use case: Implement an order lifecycle like
pending -> processing -> completed(and optionalcancelled) where each change updates fields (e.g.,completed_at) and triggers domain events.
Quick Start
Review the transition rules and state classes in references/state-management.md, then adapt the OrderState hierarchy and Transition handlers to your domain and wire them into your model with Spatie’s HasStates.
Dependency Matrix
Required Modules
None requiredComponents
references
💻 Claude Code Installation
Recommended: Let Claude install automatically. Simply copy and paste the text below to Claude Code.
Please help me install this Skill: Name: 0082-laravel-state-machines Download link: https://github.com/MrJmpl3/codex_____data_____configuration/archive/main.zip#0082-laravel-state-machines Please download this .zip file, extract it, and install it in the .claude/skills/ directory.
Agent Skills Search Helper
Install a tiny helper to your Agent, search and equip skill from 471,000+ vetted skills library on demand.