---
title: "Definitions and graphs — Lifecycle for Laravel | Roundly"
description: "Inspect states and transitions with Lifecycles::model() and definitions(), and export Mermaid or DOT diagrams with lifecycle:graph."
url: https://roundly-consulting.com/open-source/docs/lifecycle-for-laravel/definitions-and-graphs
language: en
---

[All packages](https://roundly-consulting.com/open-source.md)

[Lifecycle for Laravel](https://roundly-consulting.com/open-source/docs/lifecycle-for-laravel.md)

# Definitions and graphs

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

```php
$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

```bash
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](https://roundly-consulting.com/support-us.md)

By donating, you agree to our [donation terms](https://roundly-consulting.com/donation-terms.md).

[Support our open source work (opens in a new tab)](https://donate.stripe.com/dRmeVe8FX5PF1Qd9pXcEw00) [Join us on Patreon (opens in a new tab)](https://www.patreon.com/cw/roundly)

## 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.

[Get a quote in 48 hours](https://roundly-consulting.com/contact.md) [Browse all packages](https://roundly-consulting.com/open-source/docs/lifecycle-for-laravel.md)
