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 state and state machine behavior to Laravel Eloquent models. Represent each state as a class, automatically serialize to/from the database, and perform clean, explicit transitions with configurable rules—ideal for workflows like payments, orders, and approvals.

View on GitHub
Deep Wiki
Context7

title: Listing states weight: 3

Say you have setup the invoice model as follows:

namespace App;

use App\States\Invoice\InvoiceState;
use App\States\Invoice\Declined;
use App\States\Invoice\Paid;
use App\States\Invoice\Pending;
use App\States\Fulfillment\FulfillmentState;
use App\States\Fulfillment\Complete;
use App\States\Fulfillment\Partial;
use App\States\Fulfillment\Unfulfilled;
use Illuminate\Database\Eloquent\Model;
use Spatie\ModelStates\HasStates;

class Invoice extends Model
{
    use HasStates;

    protected $casts = [
        'state' => InvoiceState::class,
        'fulfillment' => FulfillmentState::class,
    ];
}

Get Registered States

You can get all the registered states with Invoice::getStates(), which returns a collection of state morph names, grouped by column:

[
    "state" => [
        'declined',
        'paid',
        'pending',
    ],
    "fulfillment" => [
        'complete',
        'partial',
        'unfulfilled',
    ]
]

You can also get the registered states for a specific column with Invoice::getStatesFor('state'), which returns a collection of state classes:

[
    'declined',
    'paid',
    'pending',
],

Get Default States

You can get all the default states with Invoice::getDefaultStates(), which returns a collection of state classes, keyed by column:

[
    "state" => 'App\States\Invoice\Pending',
    "fulfillment" => null,
]

You can also get the default state for a specific column with Invoice::getDefaultStateFor('state'), which returns:

'App\States\Invoice\Pending'
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.
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope
anil/file-picker
broqit/fields-ai