Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Class Carbon\Carbon not found

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
like image 478
NightMICU Avatar asked Jan 26 '14 17:01

NightMICU


4 Answers

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\

like image 108
Pathros Avatar answered Nov 01 '22 13:11

Pathros


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.

like image 51
Oli Folkerd Avatar answered Nov 01 '22 13:11

Oli Folkerd


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(); 
like image 19
Jatin Arora Avatar answered Nov 01 '22 14:11

Jatin Arora


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',

like image 13
DsRaj Avatar answered Nov 01 '22 14:11

DsRaj