NewWe open-sourced 50+ Laravel packages
Custom AI apps, agents and automation — Roundly ConsultingRoundly
All packages
Lifecycle for Laravel

Definitions and graphs

Model-level helpers and the definitions accessor expose the compiled definition, validation and diagrams:

$model = Lifecycles::model(Listing::class);          // or (Listing::class, 'status')
$model->states();          // every state
$model->initial();         // ListingStatus::Draft
$model->terminal();        // [ListingStatus::Archived]
$model->transitions();     // list<TransitionDefinition>
$model->graph();           // Mermaid (or ->graph(GraphFormat::Dot))

Lifecycles::definitions()->get(ListingLifecycle::class);       // CompiledDefinition
Lifecycles::definitions()->of($listing);                       // the definition of a model's lifecycle
Lifecycles::definitions()->validate(ListingLifecycle::class);  // ValidationReport: isValid(), errors(), warnings()
Lifecycles::definitions()->graph(ListingLifecycle::class, GraphFormat::Dot);
Lifecycles::definitions()->subjects();                         // config('lifecycle.subjects')
Lifecycles::definitions()->registered();                       // the definitions of those subjects

Graph output is deterministic, in declaration order with wildcards expanded. Mermaid uses stateDiagram-v2, marks system-only edges with ⚙ and adds a note per state listing TTL, grace, quota, dwell and seal; DOT draws rounded boxes, dashed system-only edges and double borders for terminal states. The listing lifecycle renders as:

stateDiagram-v2
    state "Draft" as s0
    state "Active" as s1
    state "Closed" as s2
    state "Expired" as s3
    state "Archived" as s4
    [*] --> s0
    s0 --> s1: publish
    s1 --> s2: close
    s2 --> s1: reopen
    s1 --> s3: expire ⚙
    s3 --> s1: reactivate
    s0 --> s4: archive
    s1 --> s4: archive
    s2 --> s4: archive
    s3 --> s4: archive
    s4 --> [*]
    note right of s1: ttl 30 days · grace 3 days · quota

From the command line

php artisan lifecycle:graph "App\Lifecycles\ListingLifecycle"
php artisan lifecycle:graph listing:status --format=dot --output=storage/listing.dot

definition is a definition class or Model:attribute (class name or morph alias); without --format the graph uses graph.default_format, and --output writes it to a file.

Lifecycles::definitions()->flush() drops the compiled definitions — for tests that redefine a lifecycle at runtime.

Show your open-source love

This package is free and MIT-licensed. If it saves you time, a one-off donation or a Patreon membership keeps it maintained, tested and documented.

More ways to support, including crypto

By donating, you agree to our donation terms.

Want this built into your product?

We integrate our packages into custom Laravel and AI builds. Tell us what you're working on and we'll reply within 48 hours.