spatie/laravel-model-states
Add robust state behavior to Laravel Eloquent models using the state pattern and state machines. Represent each state as a class, cast states transparently to/from the database, and define clear, safe transitions with configurable state logic.
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?