Laravel nWidart/laravel-modules, move an existing module to another folder

Laravel nWidart/laravel-modules, move an existing module to another folder

Problem Description:

I have a bunch of modules in Modules folder. For example "Modules/Customers"

And I need to move everything to "Modules/Core/Customers" keeping all the functionality working. Besides I must will use another subfolder for some modules:

Modules
 |___ Core
 |       |__ Customers
 |       |__ Products
 |
 |___ External
         |__ Taller

I suppose there might be three possibilities:

1- Lucky one: automatically with an artisan command, but I did not find anything on documentation (https://docs.laravelmodules.com/)

2- Manually changing files and configs, but I suppose that will leave namespaces unchanged, and that is not acceptable I would say.

3- Worst but likely: manually changing namespaces and config files.

I went for the third one as @lk77 suggested and everything was correct if I changed the folder for modules in config file module.php, except that then I cannot add several paths (or I don not find the way as it does not seem to be an array) or a more generic Modules/* as path.

'paths' => [
        /*
        |--------------------------------------------------------------------------
        | Modules path
        |--------------------------------------------------------------------------
        |
        | This path used for save the generated module. This path also will be added
        | automatically to list of scanned folders.
        |
        */

        'modules' => base_path('Modules/Core'),

Thanks a lot!!

Thanks very much

Solution – 1

Here is what I finally did. For the existing modules created previously in "Modules":

1- Move files to Modules/Core folder and change manually all references to "Modules/" for "Modules/Core" in folders "app", "bootstrap" and "Modules" (with help of replace all from sublime 🙂 ). Afterwards it was necessary to manually change references in files "composer.json" and "module.json" of each module.

2- In config/modules.php activate scan:

'scan' => [
        'enabled' => true,
        'paths' => [
            base_path('Modules/Core'),
            base_path('Modules/External'),
            base_path('vendor/*/*'),
        ],
    ],

After doing this old modules seemed to be working properly, but trying to include new ones triggered errors.

In fact the versions that included the feature to add the possibility for managing submodules/subfolders were retired shortly after the release.

So, finally I guess it is better not to use this approach with the package due to the problems.

In the end we are going to use subfolders in Laravel default tree for the core modules and use the package laravel-modules for external and optional custom modules:

app
 |
 |--- Http
 |      |
 |      |--- Controllers
 |      .         |
 |      .         |--- Customers
 |                |--- Products
 |
 |--- Models
 .        |
 .        |--- Customers
 .        |--- Products
 .
 .
Modules
 |--- Taller
 .
 .
 .
Rate this post
We use cookies in order to give you the best possible experience on our website. By continuing to use this site, you agree to our use of cookies.
Accept
Reject