internachi/modular-livewire
Livewire plugin for internachi/modular that auto-discovers and registers Livewire v3 components from your application modules. Scans each module’s src/Livewire directory and registers components as {module}::{kebab-name} with dot notation for subfolders.
Install the Package:
composer require internachi/modular-livewire
No additional configuration is needed—Laravel’s package discovery auto-registers the service provider and plugin.
Organize Your Components:
Place Livewire components in src/Livewire/ within your modules. Example structure:
app-modules/
├── billing/
│ └── src/
│ └── Livewire/
│ ├── InvoiceTable.php → billing::invoice-table
│ └── Reports/
│ └── MonthlySummary.php → billing::reports.monthly-summary
Use in Blade: Reference components using the auto-generated namespace:
<livewire:billing::invoice-table />
<livewire:billing::reports.monthly-summary />
Verify Discovery:
Run php artisan livewire:discover (if needed) or restart your Laravel server to ensure components are registered.
app-modules/users/src/Livewire/UserProfile.php.<livewire:users::user-profile />
src/Livewire/ within the relevant module.php artisan livewire:test (if available) or manually verify in Blade.users, billing). Each team owns their src/Livewire/ components.users::user-profile won’t affect billing::invoice-table.@php
$module = 'users';
$component = 'user-profile';
@endphp
<livewire:"$module::$component" />
@auth
<livewire:users::user-profile />
@endauth
internachi/modularinternachi/modular. The package extends its plugin system, so module discovery must work first.php artisan modular:list to verify modules are loaded before testing Livewire components.// app-modules/users/src/Livewire/UserProfile.php
public $name;
public function save()
{
// Logic here
}
resources/views/livewire/{module-name}/{component-name}.blade.php.
Example: resources/views/livewire/billing/invoice-table.blade.php.php artisan vendor:publish --provider="InterNACHI\ModularLivewire\ModularLivewireServiceProvider"
use Livewire\Livewire;
public function test_user_profile()
{
Livewire::test('users::user-profile')
->assertSee('User Profile');
}
my-module, the component will register as my-module::component. Ensure Blade templates use kebab-case:
<livewire:my-module::component /> <!-- Correct -->
<livewire:my_module::component /> <!-- Incorrect -->
livewire, blade).src/Livewire/: Components won’t be discovered if the directory doesn’t exist. Create it explicitly:
mkdir -p app-modules/{module}/src/Livewire/
src/Livewire/ become dot notation in the namespace:
src/Livewire/Reports/MonthlySummary.php → billing::reports.monthly-summary
php artisan view:clear
php artisan cache:clear
internachi/modular’s caching, ensure modules are re-scanned after adding new components.composer.json autoloads module classes correctly. Example:
"autoload": {
"psr-4": {
"App\\Modules\\": "app-modules/"
}
}
composer dump-autoload after adding new modules.livewire/livewire version matches:
composer require livewire/livewire:^3.0
dd(\Livewire\Livewire::getComponentClasses());
php artisan modular:list
MODULAR_LIVEWIRE_DEBUG=true
resources/views/livewire/{module}/{component}.blade.php.@livewireScripts
(This is auto-included by Livewire, but verify no conflicts exist.)ModularLivewirePlugin boot time. Consider lazy-loading modules.settings.json (VSCode):
"php.validate.executablePath": "/path/to/php",
"php.validate.run": "onType",
"php.suggest.modulePrefixes": ["App\\Modules\\"]
use App\Modules\{Module}\Livewire\{Component}; for better autocompletion.LivewireManager:
// app/Providers/AppServiceProvider.php
public function register()
{
$this->app->bind(
\InterNACHI\ModularLivewire\Contracts\LivewireManager::class,
\App\Services\CustomLivewireManager::class
);
}
ModulesRegistered event:
use InterNACHI\Modular\Events\ModulesRegistered;
public function boot()
{
event(ModulesRegistered::class, function () {
// Re-register Livewire components if modules are loaded dynamically
});
}
// app-modules/billing/src/Livewire/InvoiceTable.php
public static function shouldRegister()
{
return config('features.modular_livewire', false);
}
Livewire::component('fallback::component', \App\Modules\Fallback\Livewire\Component::class);
rules() to prevent XSS or invalid data:
public function rules()
{
return [
'name' => 'required|string|max:255',
How can I help you explore Laravel packages today?