Home Arrow Icon Knowledge base Arrow Icon Global Arrow Icon How do I manage dependencies for a module in nWidart/laravel-modules


How do I manage dependencies for a module in nWidart/laravel-modules


To manage dependencies for a module in `nwidart/laravel-modules`, you can follow these steps:

1. Install the Package:
- Run the following command to install the package via Composer:

bash
     composer require nwidart/laravel-modules
     

2. Publish the Configuration:
- Publish the package's configuration file by running:

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

3. Manage Dependencies:
- In your `module.json` file, specify the dependencies for your module. For example, if your module depends on `laravel/framework`, add the following configuration:

json
     "dependencies": {
         "laravel/framework": "^8.0"
     }
     

4. Run Composer Update:
- Run `composer update` to ensure that your dependencies are updated.

5. Autoloading:
- Add the module to the autoloading configuration in `composer.json`:

json
     "autoload": {
         "psr-4": {
             "Modules\\Blog\\": "Modules/Blog/src"
         }
     }
     

6. Run Composer Dump-Autoload:
- Run `composer dump-autoload` to refresh the autoloading.

Example Configuration:

json
{
    "name": "blog/module",
    "description": "Blog module for Laravel",
    "version": "1.0.0",
    "require": {
        "nwidart/laravel-modules": "^1.0",
        "laravel/framework": "^8.0"
    },
    "autoload": {
        "psr-4": {
            "Modules\\Blog\\": "Modules/Blog/src"
        }
    }
}

Explanation:

- Require: Specifies the dependencies for the module.
- Autoload: Configures the autoloading for the module.

By following these steps, you can effectively manage dependencies for your module in `nwidart/laravel-modules`.

Citations:
[1] https://github.com/nWidart/laravel-modules/actions/runs/9539720431/job/26290392108
[2] https://nwidart.com/laravel-modules/v1/introduction
[3] https://github.com/nWidart/laravel-modules
[4] https://nwidart.com/laravel-modules/v6/introduction
[5] https://laravel-news.com/package/nwidart-laravel-modules