Laravel Model States is a package by Spatie that adds state support to models. It combines concepts from the state pattern and state machines.

This package allows you to represent each state as a separate class, handles the serialization of states to the database behind the scenes, and allows for easy state transitions.

Here's what the Payment model would look like: use Spatie\ModelStates\HasStates; class Payment extends Model { use HasStates; protected $casts = [ 'state' => PaymentState::class, ]; }

Here's a concrete implementation of one state, the Paid state: class Paid extends PaymentState { public function color(): string { return 'green'; }}
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge. Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge.
Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Shirts painstakingly handcrafted by under-caffeinated developers. Shirts painstakingly handcrafted by under-caffeinated developers.
Community Partners