// laravel-tinker-workflows

Check Laravel production with a read-only Tinker snippet

Verify the Laravel environment, database connection, and table state with a read-only Tinker snippet before any production maintenance work.

safety July 28, 2026 12 min read Intermediate
Run Code shows the selected connection, environment label, snippet, and output on the same screen.

Direct answer

A safe production Tinker check starts with a read-only snippet, verifies the target environment, and avoids model methods that can trigger writes or side effects. In LaraBench, select a connection labeled Production and confirm the run before it executes.

When to use this

Use this for small facts: which config value is loaded, whether a table exists, which database connection is active, or whether a queue setting matches deployment expectations. Do not use it as a casual way to patch production data.

Terminal approach

In the terminal, connect exactly the way your deployment expects: SSH, Docker exec, or a remote command runner. Before Tinker, run a harmless Artisan command so you know which Laravel app is booting.

php artisan about
php artisan tinker --execute="dump([app()->environment(), config('database.default')]);"

LaraBench approach

  • Choose the production connection deliberately.
  • Read the environment label before pressing Run.
  • Start with a snippet that only reads config and schema state.
  • Use Run Code dry run for Tinker snippets that need extra write protection.
  • Treat Artisan commands as live operations; they do not use the Tinker dry-run wrapper.

Snippet

use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;

return [
    'app' => config('app.name'),
    'env' => app()->environment(),
    'database' => config('database.default'),
    'users_table_exists' => Schema::hasTable('users'),
    'users_table_has_rows' => Schema::hasTable('users')
        ? DB::table('users')->exists()
        : null,
];

Expected result

The output should prove the app, environment, default database connection, and table state without exposing user records. The final value is a boolean that confirms basic database access.

Troubleshooting

  • If the environment is wrong, stop and fix the connection target before running another snippet.
  • If the table check fails, inspect the selected database connection and migration state.
  • If a snippet needs application models, check observers and accessors before assuming the code is read-only.

Safety notes

Tinker executes real PHP inside the app. A snippet that looks like inspection can still write if it calls domain methods, lazy accessors, event dispatchers, or external services. Artisan queue retries and maintenance commands are state-changing and should be handled as deliberate commands, not dry-run assumptions.

If production runs through a container, verify the target with the Docker workflow before opening Run Code.

Run these checks in LaraBench.

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