Expand description
State machines for your Laravel Rust models: a port of spatie/laravel-model-states.
A state field is a laravel::Enum that implements State; its StateConfig sets the
default state and the allowed transitions, and HasStates transitions a model’s state
column. See the README for the guide.
Structs§
- Default
Transition - The transition used when none is configured: PHP’s
DefaultTransition. - Invalid
Config - The state config is wrong: PHP’s
InvalidConfig. - State
Changed - A state field changed: PHP’s
StateChangedevent, dispatched after the transition’shandle. - State
Config - The default state and allowed transitions of a state field: PHP’s
StateConfig. - Transition
NotAllowed - The transition’s
can_transitionreturnedfalse: PHP’sTransitionNotAllowed. - Transition
NotFound - No transition from
fromtotois allowed: PHP’sTransitionNotFound. - Unknown
State - A name that isn’t one of the base state’s states: PHP’s
UnknownState.
Enums§
- Could
NotPerform Transition - A transition couldn’t be performed: PHP’s
CouldNotPerformTransition, with its two cases.
Traits§
- HasStates
- The state methods of a model’s state columns: PHP’s
$model->state->transitionTo(...)and friends, called asmodel.transition_to(Model::state, ...). Every model has them. - Into
States - One state or several: what PHP accepts as a state class or an array of them.
- State
- A state field’s states: PHP’s abstract base state class, with one variant per concrete state class.
- State
Scopes - PHP’s
whereStateandwhereNotStatescopes on a model query. - Transition
- A custom transition: PHP’s
Transition(orDefaultTransition) subclass withhandle().
Functions§
- save_
state - Sets the state column and saves the model: what PHP’s
DefaultTransition::handle()does. - set_
default_ state - Gives
columnits default state when a create doesn’t set it: what PHP’sHasStatesdoes oncreating. Call it from the model’screatinghook. - where_
not_ state - Rows whose
columnis none ofstates: the condition of PHP’swhereNotStatescope. Combine it with|fororWhereNotState. - where_
state - Rows whose
columnis one ofstates: the condition of PHP’swhereStatescope. Combine it with|fororWhereState.