79735341

Date: 2025-08-14 11:37:59
Score: 1
Natty:
Report link

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.

Screenshot of a terminal displaying text: Carbon::now() [!] Aliasing 'Carbon' to 'Carbon\Carbon' for this Tinker session. The correct date is then displayed.

Reasons:
  • Probably link only (1):
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (0.5):
Posted by: Orchis