Home Arrow Icon Knowledge base Arrow Icon Global Arrow Icon How do I update the namespace in all files after moving a module


How do I update the namespace in all files after moving a module


To update the namespace in all files after moving a module in Laravel using `nwidart/laravel-modules`, follow these steps:

1. Publish the Configuration:
- Run the following command to publish the package's configuration file:

bash
     php artisan vendor:publish --provider="Nwidart\Modules\LaravelModulesServiceProvider"
     

2. Edit the Configuration File:
- Open the `module.php` configuration file and update the `paths` key to include the new paths. For example, if you have moved your modules to `Modules/Core`, update the `paths` key as follows:

php
     'paths' => [
         'modules' => base_path('Modules/Core'),
     ],
     

3. Save and Refresh:
- Save the changes to the `module.php` file and then run `composer dump-autoload` to refresh the autoloading.

4. Update Module Configuration:
- If you have any custom configuration files for your modules, update them to reflect the new namespace.

Example Configuration:

php
<?php

return [
    'namespace' => 'Modules',
    'stubs' => base_path('Modules/Stubs'),
    'paths' => [
        'modules' => base_path('Modules/Core'),
    ],
    'composer' => [
        'merge-plugin' => [
            'include' => ['Modules/*/composer.json'],
        ],
    ],
    'cache' => true,
    'register' => [
        'Modules\Core',
    ],
];

Explanation:

- Namespace: Sets the default namespace for generated modules.
- Stubs: Specifies the directory where the package's stubs are located.
- Paths: Specifies the directories where your modules are located.
- Composer: Configures the `composer.json` file to include the module files.
- Cache: Enables caching of module information.
- Register: Specifies which custom namespaces need to be registered by the package.

By following these steps, you can ensure that your modules are properly configured and recognized by the `nwidart/laravel-modules` package after moving them to a new location.

Citations:
[1] https://developercommunity.visualstudio.com/t/Updating-namespace-after-moving-class-fi/10639140?sort=newest
[2] https://github.com/microsoft/TypeScript/issues/12473
[3] https://stackoverflow.com/questions/8302567/how-to-change-namespace-of-entire-project
[4] https://stackoverflow.com/questions/74545403/laravel-nwidart-laravel-modules-move-an-existing-module-to-another-folder
[5] https://magento.stackexchange.com/questions/131017/module-not-working-after-namespace-magento-2