spatie/laravel-tinker-tools
Enables using short class names in Artisan Tinker sessions on older Laravel versions (built into Laravel 5.5+). Register ShortClassNames in .psysh.php and dump optimized autoload, then reference models like NewsItem::first() without full namespaces.
spatie/laravel-tinker-tools).config/ or publishes artifacts; adheres to Laravel’s "convention over configuration" by auto-detecting the Tinker environment.\Laravel\Tinker\Console\TinkerCommand), with no risk of collision with other packages or custom Artisan commands.User in both App\Models and Vendor\Package), behavior is undefined.Post, User, or Service might clash with existing code.Tinker::alias()) or upgrading Laravel.composer show laravel/framework).grep -r "class " app/).composer require spatie/laravel-tinker-tools.php artisan tinker
>>> User::first(); // Should resolve to App\Models\User
Service if both App\Services\Service and Vendor\Service exist).laravel/tinker) could theoretically override behavior. Check composer.json for duplicates.composer require laravel/tinker if missing).AppServiceProvider).composer dump-autoload).php artisan tinker --env=local (ensure environment is correct).composer show spatie/laravel-tinker-tools (verify installation).| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Laravel 5.5+ upgrade | Package conflicts with native Tinker | Remove package; use native short names. |
| Namespace collision | Short names resolve to wrong class | Use fully qualified names or aliases. |
| Autoloading issues | Short names fail to resolve | Run composer dump-autoload. |
| Package abandonment | No updates for security fixes | Monitor Spatie’s GitHub; fork if needed. |
"Short class names in Tinker are enabled via
spatie/laravel-tinker-tools. Only use in Laravel ≤5.4."
// Before:
\App\Models\User::where('active', true)->get();
// After:
User::where('active', true)->get();
User, Post, Role).How can I help you explore Laravel packages today?