State Machines
summary
Shows a concrete Laravel implementation: add a status column to invoices, map statuses to classes (Draft, Open, Paid, Uncollectible, Void) that implement an InvoiceState interface, and move finalize/pay/void/cancel logic into those classes. Controllers shrink to calls like $invoice->state()->finalize() and mail notifications run from the state methods (different emails when Uncollectible→Paid). The pattern replaces scattered conditionals, uses a base state for defaults, and demonstrably simplifies adding new transitions.
AI-written summary · about
chapters (9)
- 0:00Intro
- 2:48The Problem
- 9:19State Machine Definition
- 11:52State Machine Context
- 14:25State Pattern
- 15:42Tracking State
- 19:42Extracting State
- 20:58Using State
- 22:12Using State in Controllers
related talks
36mState Machine in Elixir with Machinery
46mState Machines (The Good, The Bad and The Ugly)
30mA short tale about state machine
36mState-machine Driven Payment Flow
41mKnowing your state machines
41mWhat If We Implemented a State Machine to Help the Little Mouse?
25mState Machines
32mDesign Patterns and Packages for Excellent Laravel Backoffices
