Fix this error
PHP: Class not found
Dasun Kalupahana 296 views
The error
Error
Error: Class "App\Services\PaymentService" not found
Why it happens
Composer's autoloader cannot find a file for that class. Usually:
- The namespace does not match the folder (
App\Servicesmust be inapp/Services). - The file or class name differs in case. Windows ignores it, Linux servers don't.
- The
usestatement is missing or wrong. - The class came with a new package and
composer installwas not run.
How to fix it
- Check that the namespace, the folder and the file name match, including upper and lower case.
- Add or fix the
useline where the class is used. - Regenerate the autoloader.
composer dump-autoload
# a package class? install dependencies
composer install
Still stuck? Send us the full error and what you tried. We add the answers here.
Learn more on the blog
Linux
Nginx 502 Bad Gateway with PHP-FPM: Causes and Fixes
A 502 page tells you nothing. It means Nginx asked PHP-FPM for...
8 min read
Laravel
Laravel Scheduler Not Running: Cron and schedule:run Fixes
You defined a scheduled task, deployed, and nothing happens. No error, no...
8 min read
Laravel
Laravel .env Configuration: env() vs config() Explained
Last updated: 9 November 2026. See the update log at the end.The...
6 min read