php 未找到碳\碳类
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21366660/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Class Carbon\Carbon not found
提问by NightMICU
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:
我最近向我的 Laravel 4 站点添加了一个包,现在任何使用 Eloquent(或至少带有任何日期/时间参考的 Eloquent)都显示 500 错误,指出:
Class 'Carbon\Carbon' Not Found.
I tried running
我试过跑步
composer install
composer update
composer dump-autoload
采纳答案by Antonio Carlos Ribeiro
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:
并不是说这对你有用,但这些是通常修复 Laravel 的步骤,当然,当问题不在你的源代码上时:
cd /your/application/dir
rm bootstrap/compiled.php
rm -rf vendor
composer install --no-dev
回答by Pathros
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):
是的,它可以作为@oli-folkerd 的答案。然而,正如在 Laracasts(Laravel 5 Fundamentals series Video 10 "forms" min 16:55)中所见,几乎在您的 ControllerClass php 文件的顶部,只需添加以下内容(如果您的 php 编辑器允许,则导入该类):
use Carbon\Carbon;
Now you can simply use Carbon
现在你可以简单地使用 Carbon
$input['published_at'] = Carbon::now();
without having to add Carbon\
无需添加 Carbon\
回答by Oli Folkerd
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.
到'aliases'app/config/app.php 中数组的底部,这将使碳库在 Laravel 中随处可用。
回答by DsRaj
For all updated version you just need to
对于所有更新的版本,您只需要
use Carbon\Carbon;
and for the global use, you can add this in app.php
对于全局使用,您可以在 app.php 中添加它
'Carbon' => 'Carbon\Carbon',
'Carbon' => 'Carbon\Carbon',
回答by Jatin Arora
You this class in controller of Laravel.
你这个类在 Laravel 的控制器中。
use Carbon\Carbon;
then you simply define the carbon command for print the current date
然后您只需定义用于打印当前日期的 carbon 命令
$date = Carbon::now();
回答by Uchiha Itachi
My problem solved by just requiring nesbot/carbon just do this:
我的问题只需要 nesbot/carbon 就解决了,只需这样做:
composer require nesbot/carbon
回答by smartrahat
I had this problem once when I updated a project from gitlab. The below command worked for me.
当我从gitlab. 以下命令对我有用。
composer dump-autoload
回答by N?s????? ?
Some times specifying prefer-distprefixed by “--” (aka “bare double dash”) at the end or suffixing at the end of create-projectalso matters while installing...
有时在最后指定prefer-dist前缀“--”(又名“裸双破折号”)或在最后指定后缀在create-project安装时也很重要...
The below command was working fine in laravel 5.5without getting an error
下面的命令在laravel 5.5 中运行良好,没有出现错误
composer create-project laravel/laravel blog "5.5.*" --prefer-dist
But when I was about to begin installing Laravel 5.6with this below command
但是当我准备使用以下命令开始安装Laravel 5.6时
composer create-project laravel/laravel blog --prefer-dist
I used to get
我曾经得到
Whoops\Exception\ErrorException : Class 'Carbon\Carbon' not found
Whoops\Exception\ErrorException : Class 'Carbon\Carbon' 未找到
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
执行上述命令后没有出现异常,安装成功,生成base64哈希键

