- How do I install Module Manager in a Laravel Starter project?
- Run `composer require nasirkhan/module-manager` in your project root. Ensure your Laravel version is 12 or 13 and PHP is 8.3+. No additional configuration is needed for basic functionality, but review the `module.json` structure for custom modules.
- Can I use this package with a non-Laravel Starter project?
- Module Manager is tightly coupled with Laravel Starter’s directory structure (e.g., `Modules/`). While you could adapt it, you’d need to manually override conventions like service providers, migrations, and namespace isolation. Consider alternatives like `laravel-modules` if you’re not using Starter.
- What’s the difference between `module:publish` and `module:diff`?
- `module:publish` copies a module’s files from the vendor directory to your `Modules/` folder for customization. `module:diff` compares the published version with the original package to show changes, helping you track modifications before updates.
- How does dependency resolution work if two modules require different versions of the same package?
- Module Manager checks `module.json` dependencies before enabling a module. If conflicts exist (e.g., `Post@1.0` requiring `Category@1.0` while `Category@2.0` is installed), the command fails with a clear error. Use `module:dependencies` to pre-check compatibility.
- What’s the safest way to update a module’s migrations after a `composer update`?
- Run `php artisan module:detect-updates {module}` to identify new migrations, then `php artisan module:track-migrations {module} --force` to baseline the updated state. Always back up your database before forcing migration tracking.
- Does Module Manager support runtime module enabling/disabling?
- Yes. Use `module:enable {module}` or `module:disable {module}` to toggle modules at runtime. Disabled modules won’t load their service providers, routes, or migrations, making it ideal for feature flags or A/B testing.
- How do I scaffold a new module with custom templates?
- Use `module:build {module-name}`. To extend templates (e.g., add middleware), override the default scaffolding in `vendor/nasirkhan/module-manager/src/ModuleBuilder.php` or publish the package’s views with `php artisan vendor:publish --tag=module-manager-templates`.
- What happens if I run `module:track-migrations --force` and it corrupts my database?
- There’s no built-in rollback for migration tracking. Always verify the baseline state with `module:check-migrations` before forcing updates. For critical systems, manually back up your migrations table (`migrations`) or use database transactions during the process.
- Can I generate tests for existing modules, or only new ones?
- You can generate tests for both. Use `module:make-test {module} {test-name}` for new modules or existing ones. The command creates a test class in `Modules/{module}/Tests/` with stubs for common module interactions (e.g., routes, controllers).
- How does Module Manager handle shared resources between modules (e.g., a `User` module used by `Post` and `Comment`)?
- Shared resources should be published once (e.g., `module:publish User`) and referenced via dependency in `module.json`. Module Manager doesn’t enforce shared logic but relies on Laravel’s autoloading. For complex shared code, consider extracting it to a standalone package or using Laravel’s `config/module-shared.php`.