- How do I create a new module in Laravel using nwidart/laravel-modules?
- Use the Artisan command `php artisan module:make ModuleName` to generate a new module with default structures for controllers, models, views, and migrations. The package handles namespace isolation automatically, so you can focus on development without manual setup.
- Can I enable or disable modules at runtime in Laravel?
- Yes, modules can be dynamically enabled or disabled using file-based or database-backed activators. For example, run `php artisan module:enable ModuleName` or `php artisan module:disable ModuleName`. This is useful for feature flags or phased rollouts.
- Does nwidart/laravel-modules support Laravel 11 and PHP 8.1+?
- Yes, the package is fully compatible with Laravel 11 and PHP 8.1+. It also supports modern tooling like Vite, Inertia.js, and Livewire. Check the [README](https://github.com/nWidart/laravel-modules) for version-specific installation instructions.
- How do I handle shared dependencies between modules in Laravel?
- Shared dependencies (e.g., models, config) require explicit coordination. Use module-specific seeds (`php artisan module:seed`) or custom seeders to manage shared schemas. For shared services, register them in the `ModuleServiceProvider` or use Laravel’s container binding.
- What’s the best way to test modules in Laravel with this package?
- Use the built-in `module:test` command to isolate module tests. Mock dependencies between modules in your test cases. For database testing, ensure module-specific seeds run in isolation or use transactions to avoid conflicts with shared test databases.
- Can I deploy modules independently in Laravel?
- Yes, modules can be deployed independently if configured for dynamic activation (file or database). However, shared dependencies (e.g., database schemas, config) may require coordinated deployments. Use Laravel Forge, Envoyer, or Docker for module-specific deployments.
- How do I migrate an existing Laravel app to use modules?
- Start incrementally by refactoring monolithic components into modules using `php artisan module:make` and `module:update`. The package supports coexistence with legacy code. For large apps, consider a phased approach—module-by-module—to avoid disruption.
- Are there performance concerns with many modules in Laravel?
- The package adds minimal overhead: ~100ms to `composer install` (via `composer-merge-plugin`) and ~50ms per request for database-backed activators. For large module counts (>50), optimize autoloading by ensuring proper namespace separation and using file-based activators where possible.
- How do I integrate module-specific assets (e.g., Vite) in Laravel?
- Use the `vite-module-loader.js` for module-specific asset compilation. Configure Vite to handle module paths, and ensure your `vite.config.js` includes the loader. The package provides native support for Vite/Laravel Mix in modern Laravel versions.
- What alternatives exist for modularizing Laravel apps?
- Alternatives include custom module systems (e.g., using Laravel packages or Spatie’s Laravel Package Tools) or third-party packages like `orchid/platform` (for admin panels) or `modules` (older, unmaintained). However, `nwidart/laravel-modules` is the most mature, actively maintained solution with deep Laravel integration.