- How do I install and set up Module Manager in a Laravel 12/13 project?
- Run `composer require nasirkhan/module-manager` to install. No additional configuration is needed for basic functionality. Start by publishing a module with `php artisan module:publish {module}` to customize its files in the `Modules/` directory. Ensure your project meets the PHP 8.3 and Laravel 12/13 requirements.
- Can Module Manager work with vanilla Laravel or only Laravel Starter?
- Module Manager is designed for Laravel Starter and relies on its architecture. While it may work in vanilla Laravel, some features like namespace isolation or dependency resolution might require manual adjustments. Test thoroughly if migrating from Laravel Starter.
- What’s the best way to scaffold a new module with all required files?
- Use the `module:build {module}` command to generate a new module skeleton, including `module.json`, migrations, config, and routes. This command also sets up the necessary directory structure in `Modules/{module}/`. Customize the module later with `module:publish`.
- How does Module Manager handle migration conflicts when updating modules?
- Module Manager tracks migration states via `module:track-migrations` and detects updates with `module:detect-updates`. Use `--force` cautiously in production, as it overwrites the baseline. Always back up your database before running migrations in production environments.
- Is there a way to enable or disable modules at runtime without downtime?
- Yes, use `module:enable {module}` or `module:disable {module}` to toggle modules dynamically. Module Manager respects Laravel’s service provider boot order via the `priority` field in `module.json`, ensuring graceful loading or unloading. Test in staging first to verify no critical dependencies are broken.
- How do I resolve dependency conflicts between modules requiring different versions of the same Laravel package?
- Module Manager does not automatically resolve Composer conflicts. Manually adjust `composer.json` or use `module:dependencies {module}` to audit dependencies. Consider using Composer’s `conflict-checker` or `why-not` commands to diagnose issues before deployment.
- Can I generate tests for my modules, and how do they integrate with Laravel’s testing tools?
- Use `module:make-test {module} {name} [--unit]` to scaffold test classes. Tests are generated in the module’s `Tests/` directory and follow Laravel’s testing conventions. Integrate with PHPUnit or Pest by extending the generated test classes and adding assertions for module-specific logic.
- What’s the rollback strategy if a module update fails in production?
- Module Manager does not provide built-in rollback for migrations or published assets. Create custom rollback scripts or use Laravel’s `migrate:rollback` for module-specific migrations. Always test rollback procedures in a staging environment mirroring production.
- How does Module Manager handle namespace collisions when publishing modules?
- Module Manager automatically rewrites namespaces during publishing to `Modules/{module}/...`, preventing collisions with vendor packages. This ensures your module’s classes, views, and configs are isolated under a unique namespace, even if they share names with other modules or Laravel core.
- Are there alternatives to Module Manager for modular Laravel applications?
- Alternatives include Laravel Modules (by N Widartono), Glow Framework, or custom solutions using Laravel Packages. Module Manager stands out for its tight Laravel Starter integration, migration tracking, and dependency resolution. Evaluate alternatives based on your need for versioning, testing, or CI/CD integration.