This is the documentation for
v1 but the latest version is
v2
.
You can switch versions in the menu on the left/at the top.
Check your current version with the following command:
composer show spatie/laravel-model-states
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.