- How do I create a new module with controllers, models, and migrations in Laravel 11?
- Use the Artisan command `php artisan module:make ModuleName` to scaffold a new module. This generates a directory structure with controllers, models, migrations, and config files. For example, `php artisan module:make Auth` creates a fully namespaced `Modules/Auth` directory with all required files.
- Can I enable or disable modules at runtime without restarting the server?
- Yes, modules support runtime activation via `module:enable` and `module:disable` commands. For dynamic toggling (e.g., feature flags), use the database-backed activation system by configuring `module_statuses` in the published config. This adds ~1ms overhead per request but avoids file system checks.
- Does nwidart/laravel-modules work with Laravel 11’s new Vite integration?
- Yes, but you’ll need to manually set up `vite-module-loader.js` for dynamic imports. Modules include their own Vite config files, and you can lazy-load module-specific assets. Check the [README’s asset section](https://github.com/nWidart/laravel-modules#assets) for integration steps.
- How do I migrate only a specific module’s database tables?
- Run `php artisan module:migrate Modules/ModuleName` to execute migrations for a single module. Use `--force` if conflicts arise. For bulk operations, `php artisan module:migrate` runs migrations for all enabled modules. Always back up your database before running migrations.
- What’s the best way to test modules in isolation?
- Use `Module::disable('ModuleName')` in your test setup to mock or exclude modules. For module-specific testing, run `php artisan module:test Modules/ModuleName` to execute tests only for that module. Pest and PHPUnit both work seamlessly with this package.
- Can I use this package with Laravel Lumen?
- Limited support exists for Lumen. Basic module structure (controllers, models) works, but features like Vite, Inertia, or database-backed activation are not supported. Refer to the [Lumen compatibility notes](https://github.com/nWidart/laravel-modules#lumen) for details.
- How do I configure module autoloading in Composer for Laravel 11?
- Since v11.0, autoloading `Modules\` is no longer required. Instead, add the `merge-plugin` to your `composer.json` under `extra` to include module-specific `composer.json` files. This ensures Composer discovers module classes without manual namespace mapping.
- What’s the performance impact of using modules vs. a flat Laravel structure?
- File-based activation (default) adds negligible overhead. Database-backed activation adds ~1ms per request. Autoloading modules via `merge-plugin` may slightly increase boot time, but this is offset by cleaner code organization and IDE autocompletion support.
- How do I upgrade from v6.x to v11.x of this package?
- Run `php artisan module:v6:migrate` to update the activation system. Review the [upgrade guide](https://github.com/nWidart/laravel-modules#upgrading) for breaking changes, such as the removal of `module_statuses.php` in favor of database-backed or file-based activation.
- Are there alternatives to nwidart/laravel-modules for Laravel modularization?
- Alternatives include `orchid/platform` (for admin panels) or `spatie/laravel-modular` (simpler but less feature-rich). However, `nwidart/laravel-modules` stands out for its Laravel 11+ support, comprehensive tooling (Artisan commands, Vite/Inertia integration), and strong test coverage. Choose based on your need for granularity vs. simplicity.