|
| 1 | +# Laravel Modules With Livewire |
| 2 | + |
| 3 | +Using [Laravel Livewire](https://github.com/livewire/livewire) in [Laravel Modules](https://github.com/nWidart/laravel-modules) package with automatically registered livewire components for every modules. |
| 4 | + |
| 5 | + |
| 6 | + |
| 7 | +### Installation: |
| 8 | + |
| 9 | +Install through composer: |
| 10 | + |
| 11 | +``` |
| 12 | +composer require codions/laravel-modules-livewire |
| 13 | +``` |
| 14 | + |
| 15 | +Publish the package's configuration file: |
| 16 | + |
| 17 | +``` |
| 18 | +php artisan vendor:publish --tag=modules-livewire-config |
| 19 | +``` |
| 20 | + |
| 21 | +### Making Components: |
| 22 | + |
| 23 | +**Command Signature:** |
| 24 | + |
| 25 | +`php artisan module:make-livewire <Component> <Module> --view= --force --inline --stub= --custom` |
| 26 | + |
| 27 | +**Example:** |
| 28 | + |
| 29 | +``` |
| 30 | +php artisan module:make-livewire Pages/AboutPage Core |
| 31 | +``` |
| 32 | + |
| 33 | +``` |
| 34 | +php artisan module:make-livewire Pages\\AboutPage Core |
| 35 | +``` |
| 36 | + |
| 37 | +``` |
| 38 | +php artisan module:make-livewire pages.about-page Core |
| 39 | +``` |
| 40 | + |
| 41 | +**Force create component if the class already exists:** |
| 42 | + |
| 43 | +``` |
| 44 | +php artisan module:make-livewire Pages/AboutPage Core --force |
| 45 | +``` |
| 46 | + |
| 47 | +**Output:** |
| 48 | + |
| 49 | +``` |
| 50 | +COMPONENT CREATED |
| 51 | +
|
| 52 | +CLASS: Modules/Core/Http/Livewire/Pages/AboutPage.php |
| 53 | +VIEW: Modules/Core/Resources/views/livewire/pages/about-page.blade.php |
| 54 | +TAG: <livewire:core::pages.about-page /> |
| 55 | +``` |
| 56 | + |
| 57 | +**Inline Component:** |
| 58 | + |
| 59 | +``` |
| 60 | +php artisan module:make-livewire Core Pages/AboutPage --inline |
| 61 | +``` |
| 62 | + |
| 63 | +**Output:** |
| 64 | + |
| 65 | +``` |
| 66 | +COMPONENT CREATED |
| 67 | +
|
| 68 | +CLASS: Modules/Core/Http/Livewire/Pages/AboutPage.php |
| 69 | +TAG: <livewire:core::pages.about-page /> |
| 70 | +``` |
| 71 | + |
| 72 | +**Modifying Stubs:** |
| 73 | + |
| 74 | +Publish the package's stubs: |
| 75 | + |
| 76 | +``` |
| 77 | +php artisan vendor:publish --tag=modules-livewire-stub |
| 78 | +``` |
| 79 | + |
| 80 | +After publishing the stubs, will create these files. And when running the make command, will use these stub files by default. |
| 81 | + |
| 82 | +``` |
| 83 | +stubs/modules-livewire/livewire.inline.stub |
| 84 | +stubs/modules-livewire/livewire.stub |
| 85 | +stubs/modules-livewire/livewire.view.stub |
| 86 | +``` |
| 87 | + |
| 88 | +**You're able to set a custom stub directory for component with (--stub) option.** |
| 89 | + |
| 90 | +``` |
| 91 | +php artisan module:make-livewire Core Pages/AboutPage --stub=about |
| 92 | +``` |
| 93 | + |
| 94 | +``` |
| 95 | +php artisan module:make-livewire Core Pages/AboutPage --stub=modules-livewire/core |
| 96 | +``` |
| 97 | + |
| 98 | +``` |
| 99 | +php artisan module:make-livewire Core Pages/AboutPage --stub=./ |
| 100 | +``` |
| 101 | + |
| 102 | +**Extra Option (--view):** |
| 103 | + |
| 104 | +**You're able to set a custom view path for component with (--view) option.** |
| 105 | + |
| 106 | +**Example:** |
| 107 | + |
| 108 | +``` |
| 109 | +php artisan module:make-livewire Pages/AboutPage Core --view=pages/about |
| 110 | +``` |
| 111 | + |
| 112 | +``` |
| 113 | +php artisan module:make-livewire Pages/AboutPage Core --view=pages.about |
| 114 | +``` |
| 115 | + |
| 116 | +**Output:** |
| 117 | + |
| 118 | +``` |
| 119 | +COMPONENT CREATED |
| 120 | +
|
| 121 | +CLASS: Modules/Core/Http/Livewire/Pages/AboutPage.php |
| 122 | +VIEW: Modules/Core/Resources/views/livewire/pages/about.blade.php |
| 123 | +TAG: <livewire:core::pages.about-page /> |
| 124 | +``` |
| 125 | +### Rendering Components: |
| 126 | + |
| 127 | +`<livewire:{module-lower-name}::component-class-kebab-case />` |
| 128 | + |
| 129 | +**Example:** |
| 130 | + |
| 131 | +``` |
| 132 | +<livewire:core::pages.about-page /> |
| 133 | +``` |
| 134 | +### Custom Module: |
| 135 | + |
| 136 | +**To create components for the custom module, should be add custom modules in the config file.** |
| 137 | + |
| 138 | +The config file is located at `config/modules-livewire.php` after publishing the config file. |
| 139 | + |
| 140 | +Remove comment for these lines & add your custom modules. |
| 141 | + |
| 142 | +``` |
| 143 | + /* |
| 144 | + |-------------------------------------------------------------------------- |
| 145 | + | Custom modules setup |
| 146 | + |-------------------------------------------------------------------------- |
| 147 | + | |
| 148 | + */ |
| 149 | +
|
| 150 | + // 'custom_modules' => [ |
| 151 | + // 'Chat' => [ |
| 152 | + // 'path' => base_path('libraries/Chat'), |
| 153 | + // 'module_namespace' => 'Libraries\\Chat', |
| 154 | + // // 'namespace' => 'Http\\Livewire', |
| 155 | + // // 'view' => 'Resources/views/livewire', |
| 156 | + // // 'name_lower' => 'chat', |
| 157 | + // ], |
| 158 | + // ], |
| 159 | +``` |
| 160 | + |
| 161 | +**Custom module config details** |
| 162 | + |
| 163 | +> **path:** Add module full path (required). |
| 164 | +> |
| 165 | +> **module_namespace:** Add module namespace (required). |
| 166 | +> |
| 167 | +> **namespace:** By default using `config('modules-livewire.namespace')` value. You can set a different value for the specific module. |
| 168 | +> |
| 169 | +> **view:** By default using `config('modules-livewire.view')` value. You can set a different value for the specific module. |
| 170 | +> |
| 171 | +> **name_lower:** By default using module name to lowercase. If you set a custom name, module components will be register by custom name. |
| 172 | +> |
| 173 | +
|
| 174 | + |
| 175 | +## Credits |
| 176 | +- This project is a modified version of [mhmiton/laravel-modules-livewire](https://github.com/mhmiton/laravel-modules-livewire), created as a fork with additional changes. |
| 177 | + |
| 178 | +## License |
| 179 | +Laravel Themes Manager is open-sourced software licensed under the [MIT license](LICENSE). |
0 commit comments