- How do I install modular-livewire in a Laravel project?
- Run `composer require internachi/modular-livewire`—the package auto-registers via Laravel’s package discovery, so no additional configuration is needed. Ensure you’re using Laravel 11+, PHP 8.3+, and internachi/modular ^3.0.
- What’s the directory structure for Livewire components in modular-livewire?
- Place Livewire components in each module’s `src/Livewire/` directory. For example, `app-modules/billing/src/Livewire/InvoiceTable.php` becomes `billing::invoice-table`. Subdirectories use dot notation (e.g., `Reports/MonthlySummary.php` → `billing::reports.monthly-summary`).
- Does modular-livewire support nested Livewire components?
- Yes, subdirectories within `src/Livewire/` are converted to dot notation in the component name. For example, `app-modules/reports/src/Livewire/Monthly/Chart.php` registers as `reports::monthly.chart`. This works recursively for any depth of nesting.
- Will this work with existing global Livewire components?
- No, modular-livewire only auto-discovers components in module-specific `src/Livewire/` directories. Existing global components must be manually migrated to modules or kept separate. There’s no backward compatibility for legacy components.
- Can I customize the naming convention (e.g., PascalCase instead of kebab-case)?
- Currently, the package enforces kebab-case for class names and dot notation for subdirectories. Custom naming resolvers aren’t built-in, but you could extend the plugin or pre-process class names in your module’s boot method if needed.
- What Laravel and Livewire versions are supported?
- modular-livewire requires **Laravel 11+**, **PHP 8.3+**, **internachi/modular ^3.0**, and **Livewire ^3.0**. It leverages Laravel’s package discovery and Livewire 3’s server-side reactivity, so downgrading isn’t supported.
- How does performance scale with hundreds of modules/components?
- The package scans modules on boot, which could add overhead for large apps. Mitigation strategies include lazy-loading components or caching discovery results. For apps with thousands of components, consider testing startup time or splitting modules into plugins.
- What if a module doesn’t have a `src/Livewire/` directory?
- Nothing breaks—modular-livewire silently skips modules without `src/Livewire/`. This is intentional to avoid errors during discovery. You can add the directory later or use a fallback like manual Livewire registration for that module.
- Are there alternatives to modular-livewire for modular Livewire components?
- If you’re not using `internachi/modular`, alternatives include manually registering components in a service provider or using Laravel’s `Livewire::component()` in a module’s boot method. However, modular-livewire automates this for modular apps, reducing boilerplate.
- How do I test components registered by modular-livewire in PHPUnit?
- Test components like any Livewire component, but ensure your module is loaded (e.g., via `Modules::load('billing')`). Use Livewire’s testing helpers (e.g., `Livewire::test('billing::invoice-table')`) in your test cases. Mock dependencies if needed.