Grant
Grant

Reputation: 2014

Class 'Carbon\Carbon\Carbon' not found in Blade partial

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

Answers (2)

Dipu Raj
Dipu Raj

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

Andy Roberts
Andy Roberts

Reputation: 945

All I had to do was add

use Carbon;

to the controller.

Upvotes: 1

Related Questions