// laravel-tinker-workflows

Inspect Eloquent models and collections in Tinker

Inspect a small Eloquent collection, select explicit columns, limit the rows, and map the result to an array that leaves private or heavy fields out.

eloquent July 28, 2026 10 min read Beginner
The prepared Tinker snippet makes the selected fields and row limit visible before it runs.

Direct answer

Query a small number of models, select only the columns you need, and map each model to an explicit array before printing or returning it. That keeps passwords, tokens, large text fields, and loaded relationships out of the output. LaraBench keeps the snippet and its output side by side.

When to use this

Use this when you need to confirm casts, scopes, statuses, selected attributes, or the shape of a small Eloquent collection. Do not use Model::all() as a quick inspection command on a large or sensitive table.

Terminal approach

php artisan tinker
use App\Models\User;

User::query()
    ->select(['id', 'name', 'status'])
    ->latest('id')
    ->limit(10)
    ->get()
    ->map(fn (User $user): array => $user->only([
        'id',
        'name',
        'status',
    ]));

Replace User and the columns with the model you are investigating. Keep the limit small until you know the query and output are safe.

LaraBench approach

  • Choose the intended connection and environment.
  • Open Run Code in Tinker mode.
  • Paste the explicit-field snippet below.
  • Run it and inspect the structured collection output.
  • Open the SQL panel when you also need to verify the query.
  • Save the snippet only if those fields are safe to reuse.

Inspection snippet

use App\Models\User;

return User::query()
    ->select(['id', 'name', 'status'])
    ->latest('id')
    ->limit(10)
    ->get()
    ->map(fn (User $user): array => $user->only([
        'id',
        'name',
        'status',
    ]));

Laravel collections also provide makeHidden([...]), but an explicit select plus only is easier to review because the allowed fields are visible at both the database and output boundaries.

Expected result

The result contains at most ten rows with only id, name, and status. The SQL panel shows one bounded select query unless a global scope, accessor, or loaded relationship adds more work.

Troubleshooting

  • If a column is missing, check the table schema and model connection.
  • If rows are unexpectedly absent, inspect global scopes and soft-delete behavior.
  • If extra queries appear, check accessors and relationships used while mapping the result.
  • If output is too large, reduce the columns and limit before rerunning.

Safety notes

A select query is read-only, but its output can still expose private data. Avoid credentials, reset tokens, personal details, payment fields, and unbounded relationships. Remember that model accessors can run application code even when the SQL itself is only a read.

Use the N+1 query workflow when inspection triggers repeated SQL, or compare two query shapes with the Eloquent benchmark workflow.

Run these checks in LaraBench.

The free app includes Run Code, Artisan commands, Docker and SSH connections, saved items, History, logs, and benchmarks.