alizharb / laravel-modular-livewire
The official Livewire bridge for Laravel Modular offering automatic discovery and registration of modular Livewire components.
Fund package maintenance!
alizharb
Installs: 6
Dependents: 0
Suggesters: 4
Security: 0
Stars: 2
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/alizharb/laravel-modular-livewire
Requires
- php: ^8.2
- alizharb/laravel-modular: ^1.0
- livewire/livewire: ^4.0
- spatie/laravel-package-tools: ^1.16
Requires (Dev)
- alizharb/laravel-themer: ^1.0
- larastan/larastan: ^3.9
- laravel/pint: ^1.24
- orchestra/testbench: ^9.5|^10.0
- pestphp/pest: *
- pestphp/pest-plugin-laravel: *
- phpstan/phpstan: *
Suggests
- alizharb/laravel-hooks: Event-driven hooks for modular communication.
- alizharb/laravel-modular: Required for modular registry and core functionality.
- alizharb/laravel-modular-filament: Filament integration for Laravel Modular.
- alizharb/laravel-modular-js: JavaScript integration for Laravel Modular.
- alizharb/laravel-themer: Theme management for modular applications.
README
Laravel Modular Livewire is the official bridge for Laravel Modular. It enables automatic discovery, registration, and first-class Artisan support for Livewire components within your modular architecture.
✨ Features
- 🔍 Automatic Discovery: Automatically scans and registers Livewire components in
Modules/*/app/Livewire. - 🏗️ Modular Artisan Command: Enhanced
make:livewirecommand with--modulesupport. - 🎨 Namespace Isolation: Components are automatically prefixed with the module name (e.g.,
<livewire:blog::post-list />). - ⚡ Performance Optimized: Intelligent component caching for zero-overhead in production.
- ✅ Strictly Typed: Fully compatible with PHPStan level 5 (and scalable to level 9).
🚀 Installation
Install the package via Composer (requires alizharb/laravel-modular):
composer require alizharb/laravel-modular-livewire
The service provider will be automatically registered. It will automatically hook into the laravel-modular registry.
📖 Usage
Generating Modular Components
Use the native make:livewire command with the --module flag to generate any Livewire 4 component type.
1. Single-File Components (Default)
The modern Livewire 4 standard. Everything in one .blade.php file.
php artisan make:livewire Status --module=Blog
- Creates:
Modules/Blog/resources/views/livewire/⚡status.blade.php - Identifier:
blog::status
2. Class-Based Components
The traditional separate Class and Template structure.
php artisan make:livewire Analytics --module=Blog --class
- Class:
Modules/Blog/app/Livewire/Analytics.php - View:
Modules/Blog/resources/views/livewire/analytics.blade.php
3. Multi-File Components (MFC)
Perfect for complex components with dedicated JS and CSS.
php artisan make:livewire Dashboard --module=Blog --mfc
- Creates:
Modules/Blog/resources/views/livewire/⚡dashboard/(Directory containing.php,.blade.php,.js,.css)
4. Page Components (Preferred for Routing)
Use the pages:: prefix for full-page components to keep them logically separated from UI fragments.
php artisan make:livewire pages::post.create --module=Blog
- Creates:
Modules/Blog/resources/views/livewire/pages/⚡create.blade.php - Identifier:
blog::pages::post.create
Routing (Livewire 4)
Laravel Modular Livewire fully supports Livewire 4's native Route::livewire() for full-page modular components.
Using Class-based Routes
use Modules\Blog\Livewire\Analytics; use Illuminate\Support\Facades\Route; Route::livewire('/blog/analytics', Analytics::class);
Using Modular Aliases
// Resolves to the single-file or class-based component Route::livewire('/blog/status', 'blog::status'); // Full-page component via modular alias Route::livewire('/blog/create', 'blog::pages::post.create'); // Example from Test module Route::livewire('/blog/create', 'blog::pages::post.create');
Using Components in Blade
In your Blade views, use the module's alias as the namespace:
{{-- Traditional or Single-file --}} <livewire:blog::status /> {{-- Specialized Page Components --}} <livewire:blog::pages::post.create /> {{-- Example from Blog module --}} <livewire:blog::pages::post.create />
⚙️ Configuration
The bridge respects your existing modular.php paths and Livewire's own configuration. No additional configuration is required.
📦 Related Packages
Explore the rest of the Laravel Modular ecosystem:
- Laravel Modular - The core modular system.
- Laravel Modular Filament - Filament integration for modular applications.
- Laravel Hooks - Event-driven hooks for modular communication.
- Laravel Themer - Theme management for modular applications.
🧪 Testing
vendor/bin/pest
🤝 Contributing
Please see CONTRIBUTING for details.
📄 License
The MIT License (MIT). Please see License File for more information.
Made with ❤️ by Ali Harb