Laravel service provider is not found

Stefan Bogdanescu

Founder & Senior Architect · 2026-06-29

Laravel Company
# Decoding the Error: Why "Laravel Service Provider Not Found" Happens When developing with Laravel, navigating the world of namespaces, service providers, and configuration files can sometimes lead to frustrating errors. The specific error you encountered—`'Krucas\Notification\NotificationServiceProvider' Not found`—is a classic symptom that points not necessarily to a physical file path issue, but rather to a breakdown in how the Laravel framework is resolving class loading through its service container mechanism. As a senior developer, understanding this requires looking beyond the physical directory structure and delving into PHP's autoloading and Composer magic. Let's break down exactly how Laravel maps those `providers` and `aliases` arrays to your actual code, and what causes this error. ## The Illusion of Physical Paths vs. Namespace Mapping You correctly noted the physical path (`C:/Apache24/htdocs/new_project/laravel/public/laravel1/app/config/app.php`) and the provider listed in the configuration. However, Laravel doesn't rely on these direct file paths for runtime class loading. Instead, it relies entirely on **namespaces** and **Composer's autoloading**. When you list a service provider in the `providers` array of `config/app.php`, you are telling the Laravel Service Container: "Please instantiate this class." For this to work, PHP must be able to locate that class file. ### How Laravel Maps Providers The mapping process is handled by two primary systems: 1. **PSR-4 Autoloading (Composer):** This is the backbone. When you use a namespace like `Krucas\Notification\NotificationServiceProvider`, Composer, via the `composer.json` file and the `autoload` section, knows exactly where to find that class definition on your filesystem. It handles the heavy lifting of mapping namespaces to physical files. 2. **Service Container Resolution:** When Laravel reads `config/app.php`, it iterates through the providers. For each entry, it attempts to use PHP's standard mechanism (`new ClassName()`). If Composer hasn't correctly mapped that namespace (i.e., if the provider class file is missing or the PSR-4 mapping is incorrect), the container throws a fatal error because it cannot find the required class definition. If you see `'Krucas\Notification\NotificationServiceProvider' Not found`, it almost always means one of two things: 1. The file defining that class does not exist at the expected location defined by your PSR-4 mapping in `composer.json`. 2. Composer is not up-to-date, and the autoloader hasn't been regenerated after adding new providers or files. ## Debugging Service Provider Failures To resolve this, stop focusing on the physical path and start focusing on the dependency graph managed by Composer. ### Step 1: Verify PSR-4 Mapping Ensure your `composer.json` file correctly maps the root namespace of your application to the correct directory. This is crucial for any package or custom service provider you implement. ```json { "autoload": { "psr-4": { "Krucas\\": "app/" // Ensure this path relates correctly to where your providers live } } } ``` ### Step 2: Run Composer Dump-Autoload After making *any* changes to provider files, configuration, or package installations, you must regenerate the autoloader map. This forces Composer to re-scan all directories and create the necessary mappings that Laravel relies on. Run this command in your terminal from the project root: ```bash composer dump-autoload ``` This step ensures that the Service Container can successfully resolve the namespace reference provided in `config/app.php` to an actual, existing PHP class file. For comprehensive guidance on managing dependencies and autoloading within a Laravel environment, always refer back to the official documentation at [laravelcompany.com](https://laravelcompany.com). ## Conclusion The confusion between physical paths and namespace resolution is common when debugging framework errors. The solution lies in trusting Composer. Laravel delegates the responsibility of finding classes to the autoloader. By ensuring your `composer.json` accurately reflects where your service providers reside, and by running `composer dump-autoload`, you ensure that the Service Container can successfully map the configuration settings from `config/app.php` into functional application logic. Focus on the dependency management layer, and the provider issue will disappear.