Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel Model States Laravel Package

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.

View on GitHub
Deep Wiki
Context7

title: State scopes weight: 1

Every model using the HasStates trait will have these scopes available:

  • whereState($column, $states) and orWhereState($column, $states)
  • whereNotState($column, $states) and orWhereNotState($column, $states)
$payments = Payment::whereState('state', Paid::class);
$payments = Payment::whereState('state', [Pending::class, Paid::class]);
$payments = Payment::whereState('state', Pending::class)->orWhereState('state', Paid::class);

$payments = Payment::whereNotState('state', Pending::class);
$payments = Payment::whereNotState('state', [Failed::class, Canceled::class]);
$payments = Payment::whereNotState('state', Failed::class)->orWhereNotState('state', Canceled::class);

When the state field has another column name in the query (for example due to a join), it is possible to use the full column name:

$payments = Payment::whereState('payments.state', Paid::class);

$payments = Payment::whereNotState('payments.state', Pending::class);
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport