- How do I add modular support to an existing Laravel Artisan command?
- Use the `Modularize` trait in your command class. This adds a `--module` option and provides a `module()` method to access the module configuration. No other changes are needed for basic modular access.
- Does this work with Laravel 12 or older versions?
- No, this package explicitly supports Laravel 13+ due to its dependency on Symfony 7.x. If you’re on Laravel 12 or earlier, you’ll need an alternative solution or to upgrade.
- Can I use this with spatie/laravel-package-tools for modular packages?
- Yes, this package is designed to integrate seamlessly with modular package architectures like spatie/laravel-package-tools. The traits work alongside package tools to ensure generated files respect module-specific paths and namespaces.
- What happens if I don’t specify the --module flag?
- Commands remain fully functional without the `--module` flag. The package ensures backward compatibility, so existing workflows aren’t disrupted during adoption.
- How does the ModularizeGeneratorCommand trait handle file generation?
- The `ModularizeGeneratorCommand` trait automatically places generated files in the correct module directory and updates namespaces dynamically. It’s optimized for Laravel’s built-in generators like `make:controller` or `make:migration`.
- What if my module structure doesn’t follow PSR-4 conventions?
- You can override the default behavior by extending the traits or customizing the `ModuleConfig` methods. The package provides hooks like `getDefaultNamespace()` to handle non-standard paths or nested modules.
- Is there a risk of vendor lock-in with internachi/modular?
- Yes, since this package depends on `internachi/modular`, changes to its API or configuration could require updates. However, the MIT license and open-source nature allow collaborative fixes, reducing long-term risks.
- Can I use this for custom file generators beyond Laravel’s defaults?
- The `ModularizeGeneratorCommand` trait is designed for Laravel’s built-in generators. For custom generators, you may need to extend the trait or manually handle module-aware paths and namespaces.
- How do I test modular commands in CI or locally?
- Mock the `ModuleConfig` instance in your tests to simulate module-specific behavior. Ensure your CI validates namespace consistency and file paths for generated artifacts across modules.
- Are there alternatives to internachi/modularize for modular Laravel packages?
- For Laravel 10/11, consider `spatie/laravel-package-tools` with custom logic or `nWidart/laravel-modules`. For Laravel 13+, this package is one of the few optimized for modular command support with minimal boilerplate.