- How do I add a --module option to my custom Laravel Artisan command?
- Use the `Modularize` trait in your command class. This automatically injects the `--module` flag and provides a `module()` method to access module configuration (name, path, namespace) when the flag is used. No additional setup is required beyond adding the trait.
- Will this work with Laravel 12 or older versions?
- No, internachi/modularize is explicitly designed for Laravel 13+ due to its reliance on Symfony 7.x console components. If you're on Laravel 12 or earlier, you’ll need to upgrade or explore alternative modular solutions like spatie/laravel-package-tools.
- Can I use this for non-generator commands like `php artisan queue:work`?
- The `Modularize` trait supports non-generator commands by adding the `--module` flag, but it doesn’t handle file system operations. For commands requiring module-aware file placement (e.g., migrations, controllers), use `ModularizeGeneratorCommand` instead, which automates directory and namespace logic.
- How does the package handle custom module paths or non-PSR-4 namespaces?
- By default, the package assumes PSR-4 module structures. For custom paths or namespaces, override the `getDefaultNamespace()` or `getModulePath()` methods in your `ModuleConfig`. This requires manual configuration but maintains flexibility for non-standard setups.
- Does this package work with spatie/laravel-package-tools?
- Yes, internachi/modularize is designed to integrate seamlessly with spatie/laravel-package-tools. It extends package commands with modular support while preserving existing functionality, making it ideal for modular monoliths or package-based architectures.
- What if my module uses a deeply nested directory structure?
- The package supports nested modules out of the box, but you may need to customize the `ModuleConfig` to reflect your exact path structure. Test thoroughly with your module hierarchy to ensure generated files land in the correct locations.
- Is there runtime overhead when using this package?
- No, internachi/modularize introduces zero runtime overhead. The traits only activate when the `--module` flag is used, and all logic is resolved during command execution without impacting performance in non-modular workflows.
- How do I test commands that use the --module flag?
- Use Laravel’s `artisan` helper in tests to simulate the `--module` flag, e.g., `artisan('your:command', ['--module' => 'module-name'])`. Mock the `ModuleConfig` if needed to isolate module-specific behavior during unit testing.
- What happens if internachi/modular gets a breaking change?
- Since internachi/modularize is tightly coupled to internachi/modular, breaking changes in the parent package may require updates. Monitor the internachi/modular changelog and test thoroughly after updates to ensure compatibility with your commands.
- Are there alternatives to this package for Laravel modular commands?
- For Laravel 12 or older, consider spatie/laravel-package-tools or custom solutions using Laravel’s service providers. For Laravel 13+, alternatives like laravel-modules or bespoke trait-based implementations exist, but internachi/modularize offers the most streamlined integration with internachi/modular’s ecosystem.