Reputation: 23
I am new on Laravel. I want write modules on different folders, not all of them inside the same folder "Modules". For example:
myProyect
|___ Clients
| |__ Module1
| |__ Module2
|
|___ Factory
|__ Part1
|_____Module1
|____ Module2
|__ Part2
|____ Module1
Is it possible? I am trying, but I only get errors. ( I started with Clients becouse not have differents sub folders like Factory ) I am doing this: Create a modular structure using nWidart steps. And it creates everything inside "Modules". I did make new dir Clients and move second module to new folder, add in composer.json: "autoload": { "psr-4": { "App\": "app/", "Modules\": "Modules/", "Clients\": "Clients/" }, And on config/app.php, I wrote: Clients\Module1\Providers\Module1ServiceProvider::class,
and when I wrote: composer dump-autoload , this error ocurrs: Class 'Clients\Module1\Providers\Module1ServiceProvider' not found
Thanks for any help.
Upvotes: 1
Views: 3368
Reputation: 5
I have something similar.
I need to use the same module in more than one project.
in the following example "Module1" is used in both Project1, Project2 and Project3. My mass structure would be close with the following:
PROJECTS
|___ Project1
|___ Project2
|___ Project3
|___ Module1
I would like to keep this structure as it follows the company's standard.
I tried some changes in my modules.php but without success:
'namespace' => '',
'paths' => [
'modules' => base_path('../..')
]
I got the following return:
PS C:\1.PHP\PROJECTS\PROJECT> php artisan module:list
Error
Class '\Teste\Providers\TesteServiceProvider' not found
at C:\1.PHP\GLOBAL\vendor\laravel\framework\src\Illuminate\Foundation\ProviderRepository.php:208
204▕ * @return \Illuminate\Support\ServiceProvider
205▕ */
206▕ public function createProvider($provider)
207▕ {
➜ 208▕ return new $provider($this->app);
209▕ }
210▕ }
211▕
1 C:\1.PHP\GLOBAL\vendor\laravel\framework\src\Illuminate\Foundation\ProviderRepository.php:144
Illuminate\Foundation\ProviderRepository::createProvider("\Teste\Providers\TesteServiceProvider")
2 C:\1.PHP\GLOBAL\vendor\laravel\framework\src\Illuminate\Foundation\ProviderRepository.php:61
Illuminate\Foundation\ProviderRepository::compileManifest()
Upvotes: 0
Reputation: 2034
You can set different modules in sub folders in Modules directory. You must set config in module.php :
'scan' => [
'enabled' => false,
'paths' => [
base_path('vendor/*/*'),
],
],
change path like this:
'scan' => [
'enabled' => false,
'paths' => [
base_path('Modules/Clients/*'),
base_path('Modules/Factory/*'),
],
],
Then change other path config:
'modules' => base_path('Modules/Clients'),
'assets' => public_path('modules/Clients'),
And namespace:
'namespace' => 'Modules\Clients',
Now if you run php artisan module:make Test
Test module set in Clients directory.
You can set modules , assets, namespace config path in controller:
\Config::set('modules.paths.modules',base_path('Modules/Clients'));
\Config::set('modules.paths.assets',base_path('modules/Clients'));
\Config::set('modules.namespace','Modules\Clients');
Check composer.json, add the autoloading to it:
"autoload": {
"psr-4": {
"App\\": "app/",
"Modules\\": "Modules/"
}
}
Then run composer dump-autoload
Upvotes: 1