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

Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future. Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future.
Community Partners