Use Laravel Modules With Livewire Registered Components

Use Laravel Modules With Livewire Registered Components  cover image

Mehediul Hassan Miton introduced a new package with which you can utilize Laravel Livewire in Laravel Modules package with automatically registered livewire components for every module.

Installation:

You can install this package through composer:

composer require mhmiton/laravel-modules-livewire

Publish the package’s configuration file:

php artisan vendor:publish --tag=modules-livewire-config

Making Components

Command Signature:

php artisan module:make-livewire <Component> <Module> --view= --force --inline --stub= --custom

Example:

php artisan module:make-livewire Pages/AboutPage Core
php artisan module:make-livewire Pages\\AboutPage Core
php artisan module:make-livewire pages.about-page Core

Force create component if the class already exists:

php artisan module:make-livewire Pages/AboutPage Core --force

Output:

COMPONENT CREATED  ?

CLASS: Modules/Core/Http/Livewire/Pages/AboutPage.php
VIEW:  Modules/Core/Resources/views/livewire/pages/about-page.blade.php
TAG: <livewire:core::pages.about-page />

Inline Component:

php artisan module:make-livewire Core Pages/AboutPage --inline

Output:

COMPONENT CREATED  ?

CLASS: Modules/Core/Http/Livewire/Pages/AboutPage.php
TAG: <livewire:core::pages.about-page />

Rendering Components

<livewire:{module-lower-name}::component-class-kebab-case />

Example:

<livewire:core::pages.about-page />

Custom Module

To create components for the custom module, should add custom modules in the config file.

The config file is located at config/modules-livewire.php after publishing the config file.

Remove comment for these lines & add your custom modules.

    /*
    |--------------------------------------------------------------------------
    | Custom modules setup
    |--------------------------------------------------------------------------
    |
    */

    // 'custom_modules' => [
    //     'Chat' => [
    //         'path' => base_path('libraries/Chat'),
    //         'module_namespace' => 'Libraries\\Chat',
    //         // 'namespace' => 'Http\\Livewire',
    //         // 'view' => 'Resources/views/livewire',
    //         // 'name_lower' => 'chat',
    //     ],
    // ],

There are also many other options and features available in this package. If you want to dig more then you can find its documentation and source code on Github

Written by

Rizwan Aslam

Founder and CEO of CodeBrisk, with years of experience building web applications with Laravel and leading a team of expert developers.

More about Rizwan
Book a free call
Book a call with CodeBrisk