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'; }}