spatie/laravel-model-states
Add state and state machine behavior to Laravel Eloquent models. Represent each state as a class, automatically serialize to/from the database, and perform clean, explicit transitions with configurable rules—ideal for workflows like payments, orders, and approvals.
This package provides a validation rule to validate incoming request data.
use Spatie\ModelStates\Validation\ValidStateRule;
request()->validate([
'state' => new ValidStateRule(PaymentState::class),
]);
// Allowing null
request()->validate([
'state' => ValidStateRule::make(PaymentState::class)->nullable(),
]);
Only valid state values of PaymentState implementations will be allowed.
How can I help you explore Laravel packages today?