Scaleup Infotech
Scaleup Infotech.
Back to Blog
Bug Fixes6 min read

Fix Laravel/PHP 'Class not found' (Composer Autoload)

Scaleup Infotech

Scaleup Infotech

Software & Marketing Agency

Apr 01, 2026
Fix Laravel/PHP 'Class not found' (Composer Autoload)
PHPLaravelComposerPSR-4

Composer maps namespaces to folders via PSR-4. When PHP cannot find a class, the namespace and the file path have drifted apart, or the autoload map is stale.

The Error

Error: Class "App\Services\PaymentService" not found

Fix 1: Regenerate the Autoload Map

After adding new classes (especially outside the framework's known paths), rebuild Composer's map:

bash
composer dump-autoload

Fix 2: Match Namespace to Folder Exactly

php
// File: app/Services/PaymentService.php
namespace App\Services;   // ✅ matches the folder (App\Services)

class PaymentService { /* ... */ }

PSR-4 maps App\ to app/. So App\Services\PaymentService must live at app/Services/PaymentService.php — with that exact casing.

Fix 3: Check composer.json PSR-4 Roots

json
"autoload": {
    "psr-4": { "App\\": "app/" }
}

Case Matters in Production

Linux servers are case-sensitive. App\services (lowercase) resolves on macOS and dies on your Ubuntu server.

Share this article:

Keep Reading

Ready to implement these ideas?

Work With Scaleup Infotech