Skip to content

Feature Request: Support for Custom Module Directories (e.g., Admin and Frontend) #2079

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
yktibrahim opened this issue May 27, 2025 · 0 comments

Comments

@yktibrahim
Copy link

Summary

Hello, I am using the nwidart/laravel-modules package and would like to create modules under two separate subdirectories, Modules/Admin and Modules/Frontend, instead of the default Modules directory. I propose adding support for custom module directories to the package while preserving all existing features of the package.

Current Behavior

Currently, the nwidart/laravel-modules package generates modules only under the Modules directory, as defined in the paths.modules setting in config/module.php. In my project, I want to organize modules into two categories:

  • Modules/Admin: For admin panel-related modules (e.g., UserManagement, Dashboard).
  • Modules/Frontend: For front-end user interface modules (e.g., Shop, Blog).

This separation would make my project more organized and modular. However, the package does not natively support multiple module directories.

Proposed Solution

I suggest extending the package to support multiple module directories through configuration and Artisan commands. For example:

  • Add support for additional module paths in config/module.php:
'paths' => [
    'modules' => base_path('Modules'),
    'admin_modules' => base_path('Modules/Admin'),
    'frontend_modules' => base_path('Modules/Frontend'),
]
  • Introduce new Artisan commands:
php artisan module:make-admin {name}: Creates a module under Modules/Admin.

php artisan module:make-frontend {name}: Creates a module under Modules/Frontend.
  • Alternatively, enhance the existing module:make command with an option to specify the target directory:
php artisan module:make {name} --path=Admin
php artisan module:make {name} --path=Frontend

This would create the module in the specified subdirectory.

Current Workaround

To achieve this in my project, I have implemented the following temporary workaround:

  • Created two custom Artisan commands, MakeAdminModule and MakeFrontendModule, in app/Console/Commands. These extend Nwidart\Modules\Commands\ModuleMakeCommand and override the module path to Modules/Admin or Modules/Frontend:
protected function getModulePath($name)
{
    return base_path('Modules/Admin') . '/' . Str::studly($name);
}

Updated composer.json to include PSR-4 autoloading for the new directories:

"autoload": {
    "psr-4": {
        "Modules\\Admin\\": "Modules/Admin/",
        "Modules\\Frontend\\": "Modules/Frontend/"
    }
}

Ensured that module service providers and other components use the correct namespaces.

While this workaround is functional, native support in the package would be more user-friendly and maintainable.

Request

Add support for multiple module directories in the package configuration.

Extend the module:make command with a --path option or introduce new commands like module:make-admin and module:make-frontend.

Ensure compatibility with existing module features (migrations, routes, views, etc.) in the new directory structure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant