Autoloading
Laravel 8
Laravel 9
Laravel 10
Laravel 11
Laravel 12
Composer Autoload Error in Laravel - How to Fix
This error occurs when Composer's autoloader cannot find classes, usually after installing packages or moving files.
The Error
Error Message
Class not found after composer install
Common Causes
- 1 Autoload files not regenerated after changes
- 2 Namespace doesn't match directory structure
- 3 Package not properly installed
- 4 PSR-4 configuration incorrect in composer.json
- 5 Cached autoloader using old paths
Solutions
1
Regenerate autoload files
Bash
# Basic regeneration
composer dump-autoload
# Optimized for production
composer dump-autoload -o
# Clear everything and reinstall
rm -rf vendor
composer install
2
Check PSR-4 in composer.json
JSON
{
"autoload": {
"psr-4": {
"App\\": "app/",
"Database\\Factories\\": "database/factories/",
"Database\\Seeders\\": "database/seeders/"
}
}
}
3
Add custom namespace
JSON
// In composer.json, add your custom namespace
"autoload": {
"psr-4": {
"App\\": "app/",
"Modules\\": "modules/"
}
}
// Then run
composer dump-autoload
4
Clear Laravel caches
Bash
php artisan clear-compiled
php artisan cache:clear
php artisan config:clear
composer dump-autoload
Need Help With Your Laravel Project?
I specialize in building custom Laravel applications, process automation, and SaaS development. Whether you need to eliminate repetitive tasks or build something from scratch, let's discuss your project.
About Hafiz
Senior Full Stack Developer. I build production software with Laravel, Filament, Vue, and AI integrations, and write about the real decisions behind shipping it.
Get in touch →