Skip to main content

Crate laravel_model_states

Crate laravel_model_states 

Source
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§

DefaultTransition
The transition used when none is configured: PHP’s DefaultTransition.
InvalidConfig
The state config is wrong: PHP’s InvalidConfig.
StateChanged
A state field changed: PHP’s StateChanged event, dispatched after the transition’s handle.
StateConfig
The default state and allowed transitions of a state field: PHP’s StateConfig.
TransitionNotAllowed
The transition’s can_transition returned false: PHP’s TransitionNotAllowed.
TransitionNotFound
No transition from from to to is allowed: PHP’s TransitionNotFound.
UnknownState
A name that isn’t one of the base state’s states: PHP’s UnknownState.

Enums§

CouldNotPerformTransition
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 as model.transition_to(Model::state, ...). Every model has them.
IntoStates
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.
StateScopes
PHP’s whereState and whereNotState scopes on a model query.
Transition
A custom transition: PHP’s Transition (or DefaultTransition) subclass with handle().

Functions§

save_state
Sets the state column and saves the model: what PHP’s DefaultTransition::handle() does.
set_default_state
Gives column its default state when a create doesn’t set it: what PHP’s HasStates does on creating. Call it from the model’s creating hook.
where_not_state
Rows whose column is none of states: the condition of PHP’s whereNotState scope. Combine it with | for orWhereNotState.
where_state
Rows whose column is one of states: the condition of PHP’s whereState scope. Combine it with | for orWhereState.