Reputation: 2014
Laravel 5.5
In my app.php
file I have an alias defined
'aliases' => [
...
'Carbon' => Carbon\Carbon::class,
],
But when trying to use it in a view, I get Class 'Carbon\Carbon\Carbon' not found
.
{{ Carbon::now()->toDateString() }}
Only when I do {{ \Carbon\Carbon::now()->toDateString() }}
does it work.
However, when I change the alias to
'aliases' => [
...
'Carbon' => 'Carbon\Carbon',
],
It works as I originally intended. Why doesn't 'Carbon' => Carbon\Carbon::class,
work as expected?
Upvotes: 2
Views: 5328
Reputation: 1894
You should use Illuminate\Support\Carbon::class
instead of Carbon\Carbon::class
.
File: config/app.php
'aliases' => [
...,
'Carbon' => Illuminate\Support\Carbon::class,
]
Upvotes: 5