Autoloading
Laravel 8
Laravel 9
Laravel 10
Laravel 11
Laravel 12
Class Not Found Exception in Laravel - Solutions
This error occurs when PHP cannot find a class that's being used, usually due to namespace issues or autoloading problems.
The Error
Error Message
Class 'ClassName' not found
Common Causes
- 1 Class namespace doesn't match directory structure
- 2 Missing use statement at top of file
- 3 Composer autoload not updated
- 4 Typo in class name
- 5 File not in correct directory
Solutions
1
Add proper use statement
PHP
use App\Models\Post;
use App\Services\PaymentService;
2
Regenerate autoload files
Bash
composer dump-autoload -o
3
Ensure namespace matches directory
PHP
// File: app/Services/PaymentService.php
namespace App\Services;
class PaymentService
{
// ...
}
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.
Currently available for 2-3 new projects
About Hafiz
Full Stack Developer from Italy. I build web applications with Laravel and Vue.js, and automate business processes. Creator of ReplyGenius, StudyLab, and other SaaS products.
View Portfolio