Laravel Magazine
Inspecting Eloquent Models from the CLI with artisan model:show

Inspecting Eloquent Models from the CLI with artisan model:show

Eric Van Johnson ·

You're three weeks into a codebase that isn't yours, staring at an Invoice model, and you need to know: what columns does this actually have, what's cast to what, and which relationships exist. The instinct is to open tinker, instantiate one, and poke at it. There's a faster path.

The command

php artisan model:show Invoice

This inspects the model class — including its database table, via the schema — and prints a clean breakdown without you writing a single line of throwaway debugging code:

Invoice
App\Models\Invoice

+-------------------+------------------------------+-------------+
| Column            | Type                         | Attributes  |
+-------------------+------------------------------+-------------+
| id                | bigint unsigned              | primary     |
| customer_id       | bigint unsigned              | foreign key |
| amount_cents      | integer                      |             |
| status            | string                       |             |
| paid_at           | timestamp                    | nullable    |
| created_at        | timestamp                    | nullable    |
| updated_at        | timestamp                    | nullable    |
+-------------------+------------------------------+-------------+

Attributes
+---------------+---------+-------+
| Name          | Cast    | Type  |
+---------------+---------+-------+
| amount_cents  | integer | int   |
| status        | enum    | string|
+---------------+---------+-------+

Relations
+------------+----------------+---------------------+
| Name       | Type           | Related              |
+------------+----------------+-----------------------+
| customer   | BelongsTo      | App\Models\Customer   |
| lineItems  | HasMany        | App\Models\LineItem   |
+------------+----------------+-----------------------+

Columns, casts, and relationships, all in one screen, sourced directly from your migrations and the model's own definitions.

Useful flags

# Show a specific model instance's actual values, not just the schema
php artisan model:show Invoice --database=mysql

# JSON output, handy for piping into another tool or a script
php artisan model:show Invoice --json

The --json flag is worth remembering if you're ever scripting something that needs to reason about model structure programmatically — a custom code generator, a documentation build step, an internal admin tool that lists model metadata.

Where this actually saves time

The real value shows up in three situations: onboarding onto an unfamiliar codebase, reviewing someone else's PR where a model changed and you want the full current picture rather than diffing migrations in your head, and debugging a cast-related bug where you need to confirm, with certainty, what a given attribute is actually cast to right now — not what you remember it being cast to from three refactors ago.

It doesn't replace reading the model source when you need to understand behavior — accessors, mutators, and scopes still require actually opening the file. But for the structural question of "what does this model look like," model:show answers it faster than tinker, a migration spelunking session, or asking in Slack.

Stay Updated

Subscribe to our newsletter

Get latest news, tutorials, community articles and podcast episodes delivered to your inbox.

Weekly articles
We send a new issue of the newsletter every week on Friday.
No spam
We'll never share your email address and you can opt out at any time.