Class Carbon\Carbon not found

大兔子大兔子 提交于 2019-12-03 07:01:28

问题


I recently added a package to my Laravel 4 site and now anything that uses Eloquent (or at least Eloquent with any reference to date/time) is showing a 500 error that states:

Class 'Carbon\Carbon' Not Found.

I tried running

composer install
composer update
composer dump-autoload

回答1:


Not saying this is work for you, but those are steps that usually fix Laravel, when the problem is not on your source code, of course:

cd /your/application/dir

rm bootstrap/compiled.php

rm -rf vendor

composer install --no-dev



回答2:


Yes, it can work as @oli-folkerd 's answer. However, as seen in Laracasts (Laravel 5 Fundamentals series Video 10 "forms" min 16:55), almost in top of your ControllerClass php file, just add the following (or import the class if your php editor allows you do so):

use Carbon\Carbon;

Now you can simply use Carbon

$input['published_at'] = Carbon::now();

without having to add Carbon\




回答3:


you need to add the line:

'Carbon' => 'Carbon\Carbon',

to the bottom of the 'aliases' array in app/config/app.php this will make the carbon library available everywhere in laravel.




回答4:


For all updated version you just need to

use Carbon\Carbon;

and for the global use, you can add this in app.php

'Carbon' => 'Carbon\Carbon',




回答5:


You this class in controller of Laravel.

use Carbon\Carbon;

then you simply define the carbon command for print the current date

$date = Carbon::now(); 



回答6:


My problem solved by just requiring nesbot/carbon just do this:

composer require nesbot/carbon



回答7:


I had this problem once when I updated a project from gitlab. The below command worked for me.

composer dump-autoload



回答8:


Some times specifying prefer-dist prefixed by “--” (aka “bare double dash”) at the end or suffixing at the end of create-project also matters while installing...

The below command was working fine in laravel 5.5 without getting an error

composer create-project laravel/laravel blog  "5.5.*" --prefer-dist

But when I was about to begin installing Laravel 5.6 with this below command

composer create-project laravel/laravel blog --prefer-dist

I used to get

Whoops\Exception\ErrorException : Class 'Carbon\Carbon' not found

After referring to the official Installation Documentation

composer create-project --prefer-dist laravel/laravel blog

After executing the above command there were no exceptions raised, therefore installation succeeded, thereby generating a base64 hash key



来源:https://stackoverflow.com/questions/21366660/class-carbon-carbon-not-found

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!