- How do I install Laravel Tinker in my Laravel project?
- Run `composer require laravel/tinker` in your project root. No additional configuration is needed—just use `php artisan tinker` to start the REPL. It integrates seamlessly with Laravel’s Artisan CLI.
- Can I use Laravel Tinker with Laravel 13 or the latest version?
- Yes, Tinker supports Laravel 13+ with version 3.x, which requires PHP 8.1+. Check the [Laravel documentation](https://laravel.com/docs/artisan#tinker) for version-specific details and compatibility.
- What’s the difference between `php artisan tinker` and `php artisan tinker --execute`?
- The `--execute` flag runs a single command and exits immediately, ideal for quick one-liners like `php artisan tinker --execute='User::all()'`. Without it, you enter an interactive REPL session for deeper exploration.
- How do I debug Eloquent models or database queries in Tinker?
- Tinker automatically casts Eloquent models for readable output. Run queries like `User::where('active', true)->get()` and inspect results interactively. Use `dd()` or `dump()` for detailed debugging.
- Is Laravel Tinker safe to use in production environments?
- No, Tinker is **not** designed for production. It exposes the Laravel service container and database interactively, which is a security risk. Restrict access via `APP_ENV` checks or middleware in production.
- How can I customize Tinker’s output or add custom casters?
- Extend Tinker’s behavior by defining custom casters in your `AppServiceProvider`. Use `Tinker::casts()` to format domain-specific types (e.g., `Carbon` instances or custom collections).
- Why do I see PsySH trust prompts when using Tinker, and how do I disable them?
- PsySH (the underlying REPL) prompts for trust if files change. Disable it globally by setting `PSYSH_TRUST_PROJECTS=1` in your environment or use `Tinker::avoidTrustPrompts()` in a service provider.
- Can I use Laravel Tinker to test Laravel queues or jobs interactively?
- Yes! Dispatch jobs directly in Tinker (e.g., `dispatch(new ProcessPodcast))` and inspect their state. It’s perfect for debugging job logic without writing full test scripts.
- Are there alternatives to Laravel Tinker for debugging?
- For Laravel, alternatives include **Laravel Debugbar** (browser-based debugging) or **PHP’s built-in CLI** with manual `require` calls. However, Tinker is uniquely optimized for Laravel’s ecosystem with Eloquent casting and service container access.
- How do I integrate Tinker into CI/CD pipelines or test environments?
- Tinker is primarily a dev tool, but you can enable it in CI for debugging by checking `APP_ENV` or `DEBUG` flags. Use `--execute` for one-off commands in scripts (e.g., `php artisan tinker --execute='Test::run()'`).