Laravel-modules: ServiceProvider Not Found

Created on 18 Jul 2016  路  9Comments  路  Source: nWidart/laravel-modules

I'd like to say this is nice module.
It has an error that says afte creating Backend module.

Class 'CustomNameSpace\Backend\Providers\BackendServiceProvider' not found.

L v5.2.39

Most helpful comment

You just linked 2 different psr-4 autoload section. You can only use one of them, keep the first one.

Also run a composer dumpautoload and php artisan clear-compiled.

All 9 comments

It looks like it couldn't find your namespace. Double check if the case on CustomNameSpace is the same everywhere.

Also try with the default Modules namespace to see if we can pinpoint the issue.

Hi,
I have changed namespace to default "Modules" uppercase "M", I still got the same issue.
Class 'Modules\Backend\Providers\BackendServiceProvider' not found

Changing the namespace alone won't do anything, as it's PSR-4, your folder structure needs to match, or your composer.json file needs to be adapted.

This is composer.json on root directory

    "psr-4": {
        "App\\": "app/",
        "Modules\\": "modules/"
    }

Am I missing anything!

You need to check the namespaces yes.

The folder structure needs to match the namespace.

  • Modules folder exists in root directory /modules
  • composer.json root directory contents as follows:
"psr-4": {
    "App\\": "app/",
    "Modules\\": "modules/"
}
  • Folder stucture trace to BackendServiceProvider as follows:

/modules/Backend/Providers/BackendServiceProvider.php

  • namespace declaration in BackendServiceProvider.php

  • composer.json content for Backend module as related to psr-4:

"autoload": {
"psr-4": {
"Modules\Backend\": ""
}
}

You just linked 2 different psr-4 autoload section. You can only use one of them, keep the first one.

Also run a composer dumpautoload and php artisan clear-compiled.

Thanks! That fixed it!

Awesome 馃憤

Was this page helpful?
0 / 5 - 0 ratings