The optimize-autoloader
addition to composer.json works for custom classes like Models, but not for vendor classes like Carbon.
This can be achieved by publishing Tinker's config file, and adding Carbon as an alias.
Run php artisan vendor:publish --provider="Laravel\Tinker\TinkerServiceProvider"
to generate `config/tinker.php` if the file doesn't already exist.
Edit the alias
array in this file to alias carbon:
'alias' => [
'Carbon\Carbon' => 'Carbon',
]
Then, run composer dump-autoload
.
Tinker should now automatically alias Carbon, allowing Carbon::now()
to work without using the full namespace.