Home > Blockchain >  nWidart/laravel-modules, how to put modules folder outside laravel folder
nWidart/laravel-modules, how to put modules folder outside laravel folder

Time:02-03

`I'm kind of new to laravel, I have a project that I made modular using nWidart/laravel-modules.

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()

CodePudding user response:

If I understand correctly, it seems like you want to use a module in multiple projects so that you don't need to duplicate the code within each module.

In order to achieve this you could create your own git repository called my-module for example and install this via composer within each project.

There's an article in the Laravel Modules documentation which highlights how to do this: https://docs.laravelmodules.com/v9/publishing-modules

The article also explains how to install private packages in case you don't want your source code to be public.

  • Related