laravel/tinker
Laravel Tinker provides an interactive REPL (powered by PsySH) for Laravel applications. Quickly run PHP and Artisan code, inspect models and services, and debug in a live console with your app’s full context loaded.
laravel/tinker) and integrates automatically with Laravel’s artisan command. No manual setup required beyond composer require.php artisan tinker, with optional --execute flag for one-off commands (e.g., php artisan tinker --execute="User::first()->toJson()").HtmlString, Stringable) for pretty-printing objects and whitelisted commands (e.g., migrate:install) for safety.system() calls) could exploit the app. Mitigate via:
artisan cache:clear in production).APP_ENV=production).--execute in CI).--execute performance and resource usage.dd() in production-like contexts)?User::class pretty-printing)?php artisan tinker --execute="DB::table('users')->count()").php artisan serve + manual script testing.php artisan + scripts or Laravel Forge/Envoyer.composer require laravel/tinker
Psy\Configuration in AppServiceProvider:
use App\Models\User;
Psy\Configuration::getCasters()->addCaster(User::class, function (User $user) {
return "User#{$user->id}: {$user->email}";
});
getWhitelistedCommands() in a custom Tinker command.if ($this->app->environment('production')) {
throw new \RuntimeException('Tinker disabled in production.');
}
STDIN is interactive (e.g., -t flag in Docker).Artisan::call() with destructive commands).php artisan tinker --execute="if (Schema::hasTable('failed_jobs')) exit(0); else exit(1);"
.env:
TINKER_ENABLED=false
tinker command in app/Console/Kernel.php:
protected $commands = [
// ... other commands
// \Laravel\Tinker\TinkerCommand::class, // Commented out
];
psy/psysh for breaking changes (e.g., v0.12.x in v3.x).config/tinker.php).Class not found: Ensure Laravel’s autoloader is loaded (Tinker handles this automatically).TTY errors: Use --no-interaction or yes "" | php artisan tinker in scripts.Memory leaks: Restart Tinker or the PHP process if sessions hang.Psy\Configuration::getOutput() to inspect shell state.storage/logs/laravel.log for Tinker-related errors.dd() or exit() in Tinker sessions.How can I help you explore Laravel packages today?