0% found this document useful (0 votes)
113 views4 pages

Class 'App - HTTP - Controllers - Carbon' Not Found

The document discusses an issue where the OP is getting an error saying "Class 'App\Http\Controllers\Carbon' not found" when trying to use the Carbon class in Laravel. Through discussion, it is determined that the error is occurring in a controller file, not the AppServiceProvider file as originally thought. The solution is to add a "use Carbon\Carbon;" statement at the top of the controller file to properly namespace the Carbon class.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
113 views4 pages

Class 'App - HTTP - Controllers - Carbon' Not Found

The document discusses an issue where the OP is getting an error saying "Class 'App\Http\Controllers\Carbon' not found" when trying to use the Carbon class in Laravel. Through discussion, it is determined that the error is occurring in a controller file, not the AppServiceProvider file as originally thought. The solution is to add a "use Carbon\Carbon;" statement at the top of the controller file to properly namespace the Carbon class.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

2/10/22, 14:25 Class 'App\Http\Controllers\Carbon' not found

18601 15 LARAVEL

Team feeling unorganized? Bring all your work


ctwx
together into one app and maximize
Posted 5 years ago
productivity.

ads via Carbon


Class 'App\Http\Controllers\Carbon' not found

I added a validator to AppServiceProvider.php, as described in this article:


https://medium.com/@jagadeshanh/image-upload-and-validation-using-laravel-and-vuejs-
e71e0f094fbb

I added the "use" statements, but for some reason Carbon cannot be found. I also tried use
\Carbon\Carbon; instead, which didn't work either.

So... I'm out of ideas. What am I missing here?

JackJones BEST ANSWER


Posted 5 years ago

In the Controller file

You're in the Controller namespace, so you're referencing carbon in a Controller without a use

1 Reply

JackJones
Posted 5 years ago

Where have you placed the code?

The fact your in the Controller namespace says you've done something wrong

1 Reply

Dry7
Posted 5 years ago

You have a folder vendor/nesbot/carbon?


And try

Copy Code
compose dump

https://laracasts.com/discuss/channels/laravel/class-apphttpcontrollerscarbon-not-found 2/7
2/10/22, 14:25 Class 'App\Http\Controllers\Carbon' not found

1 Reply

ctwx
Posted 5 years ago

@JackJones I placed it in app/providers/AppServiceProvider.php.

@Dry7 yes, the carbon folder exists.


I did, but it doesn't work. Before I created this thread, I already
tried composer dump-autoload

Reply

Cronix
Top 10 Leaderboard Posted 5 years ago

I believe it's use Carbon\Carbon; with no first slash

2 Reply

JackJones
Posted 5 years ago

@ctwx It's looking in the Controller namespace, so where did you put the use in the file?

1 Reply

ctwx
Posted 5 years ago

@Cronix nope, doesn't work either. I tried that first.

(1/1) FatalThrowableError
Class 'App\Http\Controllers\Carbon' not found

Reply

ctwx
Posted 5 years ago

@JackJones below the namespace. See here: https://pastebin.com/TZE02RGx

That's why I tried it with a backslash before Carbon. That should right, shouldn't it?

Reply

https://laracasts.com/discuss/channels/laravel/class-apphttpcontrollerscarbon-not-found 3/7
2/10/22, 14:25 Class 'App\Http\Controllers\Carbon' not found

JackJones BEST ANSWER


Posted 5 years ago

In the Controller file

You're in the Controller namespace, so you're referencing carbon in a Controller without a use

1 Reply

ctwx
Posted 5 years ago

Ohhh damn!!

The error is not coming from that file... Thanks guys.

Reply

Snapey
Top 10 Leaderboard Posted 5 years ago

This App\Http\Controllers in the errors is telling me this is nothing to do with the AppServiceprovider.

Look at the error stack and see which controller it is in.

Then put use Carbon\Carbon at the top

Edit: 2 minutes too late

Reply

Cronix
Top 10 Leaderboard Posted 5 years ago

I think you're a bit confused. You're not even using carbon in the AppServiceProvider. The problem is
somewhere else in your code that you are using Carbon. use Carbon\Carbon; is correct, btw. I use it
all over the place.

1 Reply

Snapey
Top 10 Leaderboard Posted 5 years ago

@ Nickels

https://laracasts.com/discuss/channels/laravel/class-apphttpcontrollerscarbon-not-found 4/7
2/10/22, 14:25 Class 'App\Http\Controllers\Carbon' not found

In laravel 5.5 laravel got pulled in as a dependency of the framework and should be use with
use Illuminate\Support\Carbon;

surely not... that would be a major breaking change (not mentioned in release notes)

1 Reply

ctwx
Posted 5 years ago

The error was not coming from the AppServiceProvider, it was in my Controller.

First, there was a missing use in the AppServiceProvider, then the next error was in my controller. But
I didn't realize it and thought it was there... :-/ Sorry...

Reply

JackJones
Posted 5 years ago

I assume they meant Carbon, but yea, seems that way

https://github.com/laravel/framework/blob/5.5/src/Illuminate/Support/Carbon.php

Reply

Snapey
Top 10 Leaderboard Posted 5 years ago

Illuminate/Support/Carbon.php extends Carbon/Carbon and adds some json serialisation methods

Carbon/Carbon is still available as before

2 Reply

Please sign in or create an account to participate in this conversation.

https://laracasts.com/discuss/channels/laravel/class-apphttpcontrollerscarbon-not-found 5/7

You might also like