Blog Detail

17

Mar
Use Laravel Modules With Livewire Registered Components  cover image

arrow_back Use Laravel Modules With Livewire Registered Components

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

Published at : 17-03-2022

Author : Rizwan Aslam
AUTHOR
Rizwan Aslam

I am a highly results-driven professional with 12+ years of collective experience in the grounds of web application development especially in laravel, native android application development in java, and desktop application development in the dot net framework. Now managing a team of expert developers at Codebrisk.

Launch your project

Launch project