Back to Error Center
Class 'Carbon\Carbon' not found
Error Message
Class "Carbon\Carbon" not found
Cause
The Carbon library isn't installed or the class isn't imported. Carbon is included with Laravel but needs to be imported with use.
Solution
Add use Carbon\Carbon; at the top of the file. Run composer install if dependencies are missing. Check composer.json includes nesbot/carbon.
Code Example
Fix
<?php
use Carbon\Carbon; // Add this import
$date = Carbon::now();
$ago = Carbon::parse('2024-01-01')->diffForHumans();
// Or use the helper
$date = now(); // Returns Carbon instance
$ago = now()->subDays(7)->diffForHumans();
Debugging Steps
- Add the use Carbon\Carbon; import statement
- Run composer install to restore dependencies
- Check composer.json for nesbot/carbon
- Run composer dump-autoload
Prevention
Always import Carbon class. Use the now() and today() helpers for convenience. Keep dependencies up to date.