Class Not Found Error in Laravel – Easy Fix (2025)
One of the most common Laravel errors is:
Class 'App\Http\Controllers\SomethingController' not found
Don’t worry! This usually happens when Laravel cannot find your controller class. Let’s fix it step by step. ✅
🔍 Why Does This Error Happen?
The controller file doesn’t exist in the correct folder.
The namespace in your controller file is incorrect.
Laravel’s autoload files are outdated.
🛠 Step-by-Step Fix
1. Run Autoload & Clear Cache
Open your terminal inside the project folder and run:
composer dump-autoload
php artisan optimize:clear
👉 This refreshes Laravel’s class map and clears old cached files.
2. Check Namespace in Your Controller
Open your controller file (example: SomethingController.php) and make sure the namespace is correct:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class SomethingController extends Controller
{
public function index()
{
return view('welcome');
}
}
✅ The first line must be:
namespace App\Http\Controllers;
3. Check Route File
In routes/web.php, make sure you are calling the controller like this:
use App\Http\Controllers\SomethingController;
Route::get('/something', [SomethingController::class, 'index']);
🎯 Pro Tips for Beginners
Always keep controller names and files the same (Example: SomethingController.php → SomethingController).
If you rename a controller, update routes too.
Run composer dump-autoload whenever you create or move classes.
✅ Final Words
If you still see this error after following the above steps, check for spelling mistakes or missing files. Most of the time, it’s just a namespace or cache issue.