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:
composer dump-autoloadFix 2: Match Namespace to Folder Exactly
// 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
"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.
