Composer Autoload Laravel 5.5

Composer Autoload Laravel 5.5

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

Composer Autoload Laravel 5.5

Upgrading from Laravel 5.1 to 5.5 often introduces subtle breaking changes in how the framework handles file discovery and autoloading. When you encounter an error indicating that a class cannot be found, despite your namespace being correct and PhpStorm recognizing it perfectly, the issue usually lies not in your code, but in how Composer generates its autoload files based on your composer.json.

In Laravel 5.1, the default autoload configuration was quite permissive regarding directory structures. However, by version 5.5, the framework tightened these expectations. Specifically, Laravel 5.5 requires that all classes mapped via PSR-4 must reside in directories that are strictly recognized as part of the application's root namespace hierarchy.

The error you are encountering stems from a mismatch between your custom directory structure and the strict autoloading rules enforced by Laravel 5.5. In your composer.json, you have defined:

"autoload": {
    "classmap": [
        "database/seeds",
        "database/factories"
    ],
    "psr-4": {
        "App\\": "app/",
        "Nob\\": "nob/"
    }
}

While this configuration worked in 5.1, Laravel 5.5 expects the nob directory to be a direct child of the project root if you want it to autoload classes outside the standard App namespace without further qualification. However, there is a critical nuance often missed during upgrades: Laravel 5.5 automatically registers its own autoloader logic that can conflict with custom PSR-4 mappings if the directory structure isn't exactly as expected.

The specific error message suggests that the autoloader cannot find Nob\Payeezy\Types\Authorization. Even though PhpStorm's IDE is smart enough to resolve the namespace visually, PHP at runtime relies entirely on the file generated by vendor/autoload.php.

When you run composer dump-autoload, Composer reads your configuration and generates a map of class names to file paths. If the directory structure does not match the namespace definition exactly, or if Laravel's internal autoloading logic overrides the custom one incorrectly, classes will vanish.

In many cases, the issue arises because Laravel 5.5 expects the nob folder to be treated similarly to how it treats the app and config folders. If your nob directory is not directly in the root, or if there are permission issues preventing Composer from scanning it (less likely but possible), the class map fails to include the file.

However, the most common solution for this specific transition involves ensuring that the custom namespace is explicitly registered and that the directory structure aligns with the PSR-4 standard. If you are using a folder named nob directly in your root, ensure that the composer.json is located in that same root and that no symlinks or complex directory structures are interfering with the path resolution.

If you have verified the path and the namespace declaration inside the file matches the PSR-4 definition exactly (e.g., namespace Nob\Payeezy\Types;), try running:

composer dump-autoload -d /path/to/your/project

The -d flag ensures you are dumping the autoload for the specific directory where your composer.json resides, which is crucial if you have multiple projects or complex setups. After running this command, restart your PHP CLI or clear your IDE cache to ensure the new map is loaded.

If the problem persists despite a correct file path and namespace, it may be necessary to adjust the Laravel 5.5 configuration to explicitly include your custom directory in the bootstrap process or verify that no other autoloaders are shadowing your custom PSR-4 rules. Understanding these structural requirements prevents friction when upgrading legacy projects to newer versions of the framework.

Our network