laravel/tinker
Laravel Tinker provides an interactive REPL for Laravel, letting you run PHP code and interact with your application from the command line via Artisan tinker. Great for debugging, testing ideas, and exploring models, services, and configuration.
Laravel Tinker is a lightweight, tightly integrated REPL tool built for Laravel’s ecosystem, making it a perfect fit for:
Key strengths:
Potential limitations:
Tinker integrates via Composer and requires zero manual setup beyond:
composer require laravel/tinker
Compatibility:
| Laravel Version | PHP Version | Notes |
|---|---|---|
| 7.x–13.x | 8.1–8.5 | Fully supported (v2.x–v3.x) |
| 10.x–12.x | 8.1–8.4 | Optimized for performance (v2.10+) |
| 13.x | 8.2+ | Requires v3.x (PHP 8.1+ minimum) |
Key integration points:
php artisan tinker, with optional --execute for one-off commands.app()->make()).User::find(1) displays formatted output).Tinker::casts() for domain-specific types.Feasibility risks:
composer require).| Risk Area | Severity | Mitigation Strategy |
|---|---|---|
| PsySH Trust Prompts | Medium | Configure PSYSH_TRUST_PROJECTS=1 or patch via Tinker::avoidTrustPrompts(). |
| Performance Overhead | Low | Minimal; PsySH is optimized for REPL use. |
| Security in Prod | High | Blocklist Tinker in production (e.g., via APP_ENV checks). |
| Dependency Bloat | Low | Tinker is ~1MB; PsySH is ~2MB (acceptable for dev tools). |
| IDE Compatibility | Medium | Document workarounds (e.g., use CLI directly). |
Critical questions for the TPM:
Tinker is optimized for the Laravel stack and integrates cleanly with:
tinker and --execute flags.dispatch(new MyJob()))..env and config values dynamically.Non-Laravel stack considerations:
| Phase | Action | Effort | Notes |
|---|---|---|---|
| Evaluation | Install and test in a dev environment (composer require). |
Low | Verify PsySH compatibility. |
| Adoption | Document php artisan tinker in dev guides. |
Medium | Include common use cases (e.g., model queries). |
| Customization | Extend casters or prompts if needed (e.g., for custom Eloquent models). | High | Requires Tinker service provider hooks. |
| Restriction | Block in production via APP_ENV or middleware. |
Low | Add to app/Providers/AppServiceProvider. |
Rollout strategy:
| Component | Compatibility Status | Notes |
|---|---|---|
| Laravel 10–13 | ✅ Fully supported (v2.x–v3.x) | Use v3.x for Laravel 13. |
| PHP 8.1–8.5 | ✅ Supported | v3.x drops PHP 8.0. |
| Eloquent 9–10 | ✅ Automatic model casting | Supports hidden/appended attributes. |
| Custom Facades | ✅ Accessible via app() or Facade::class |
No extra config needed. |
| Queue Workers | ⚠️ Limited (dev-only) | Avoid in production. |
| API Testing | ❌ Not designed for HTTP requests | Use Postman/Insomnia for API debugging. |
Known conflicts:
composer update psy/psysh).migrate:install).composer.json and run composer update.AppServiceProvider:
Tinker::casts([
App\Models\CustomModel::class => function ($model) {
return "Custom: {$model->id}";
}
]);
AppServiceProvider:
if (app()->environment('production')) {
Artisan::disableCommand('tinker');
}
| Task | Frequency | Effort | Owner |
|---|---|---|---|
| Dependency Updates | Quarterly | Low | DevOps/TPM |
| PsySH Patches | As needed | Medium | Backend Team |
| Caster Extensions | Rare | High | Domain-Specific Team |
| Security Audits | Biannual | Medium | Security Team |
Maintenance considerations:
Common support requests:
User::with('posts')->find(1) + tab-complete.How can I help you explore Laravel packages today?