Skip to content

Commit 9d7ef56

Browse files
committed
First commit
0 parents  commit 9d7ef56

13 files changed

+1059
-0
lines changed

Diff for: LICENSE.md

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2023 https://github.com/fabioassuncao
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Diff for: README.md

+179
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
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).

Diff for: composer.json

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"name": "codions/laravel-modules-livewire",
3+
"description": "Using Laravel Livewire in Laravel Modules package with automatically registered livewire components for every modules.",
4+
"keywords": [
5+
"laravel",
6+
"modules",
7+
"module",
8+
"livewire",
9+
"nwidart",
10+
"mhmiton"
11+
],
12+
"license": "MIT",
13+
"authors": [
14+
{
15+
"name": "Fábio Assunção",
16+
"email": "[email protected]"
17+
}
18+
],
19+
"type": "library",
20+
"require": {
21+
"php": ">=7.3"
22+
},
23+
"require-dev": {
24+
"laravel/framework": "^7.0|^8.0|^9.0|^10.0"
25+
},
26+
"extra": {
27+
"laravel": {
28+
"providers": [
29+
"Codions\\LaravelModulesLivewire\\LaravelModulesLivewireServiceProvider"
30+
]
31+
}
32+
},
33+
"autoload": {
34+
"psr-4": {
35+
"Codions\\LaravelModulesLivewire\\": "src/"
36+
}
37+
},
38+
"minimum-stability": "dev",
39+
"prefer-stable": true
40+
}

Diff for: config/modules-livewire.php

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
return [
4+
5+
/*
6+
|--------------------------------------------------------------------------
7+
| Class Namespace
8+
|--------------------------------------------------------------------------
9+
|
10+
*/
11+
12+
'namespace' => 'Http\\Livewire',
13+
14+
/*
15+
|--------------------------------------------------------------------------
16+
| View Path
17+
|--------------------------------------------------------------------------
18+
|
19+
*/
20+
21+
'view' => 'Resources/views/livewire',
22+
23+
/*
24+
|--------------------------------------------------------------------------
25+
| Custom modules setup
26+
|--------------------------------------------------------------------------
27+
|
28+
*/
29+
30+
// 'custom_modules' => [
31+
// 'Chat' => [
32+
// 'path' => base_path('libraries/Chat'),
33+
// 'module_namespace' => 'Libraries\\Chat',
34+
// // 'namespace' => 'Http\\Livewire',
35+
// // 'view' => 'Resources/views/livewire',
36+
// // 'name_lower' => 'chat',
37+
// ],
38+
// ],
39+
40+
];

Diff for: src/Commands/LivewireMakeCommand.php

+96
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
<?php
2+
3+
namespace Codions\LaravelModulesLivewire\Commands;
4+
5+
use Illuminate\Console\Command;
6+
use Illuminate\Support\Facades\File;
7+
use Codions\LaravelModulesLivewire\Traits\ComponentParser;
8+
9+
class LivewireMakeCommand extends Command
10+
{
11+
use ComponentParser;
12+
13+
protected $signature = 'module:make-livewire {component} {module} {--view=} {--force} {--inline} {--stub=} {--custom}';
14+
15+
/**
16+
* The console command description.
17+
*
18+
* @var string
19+
*/
20+
protected $description = 'Generate Livewire Component.';
21+
22+
/**
23+
* Execute the console command.
24+
*
25+
* @return int
26+
*/
27+
public function handle()
28+
{
29+
if (! $this->parser()) {
30+
return false;
31+
}
32+
33+
if (! $this->checkClassNameValid()) {
34+
return false;
35+
}
36+
37+
if (! $this->checkReservedClassName()) {
38+
return false;
39+
}
40+
41+
$class = $this->createClass();
42+
43+
$view = $this->createView();
44+
45+
if ($class || $view) {
46+
$this->line("<options=bold,reverse;fg=green> COMPONENT CREATED </> 🤙\n");
47+
48+
$class && $this->line("<options=bold;fg=green>CLASS:</> {$this->getClassSourcePath()}");
49+
50+
$view && $this->line("<options=bold;fg=green>VIEW:</> {$this->getViewSourcePath()}");
51+
52+
$class && $this->line("<options=bold;fg=green>TAG:</> {$class->tag}");
53+
}
54+
55+
return false;
56+
}
57+
58+
protected function createClass()
59+
{
60+
$classFile = $this->component->class->file;
61+
62+
if (File::exists($classFile) && ! $this->isForce()) {
63+
$this->line("<options=bold,reverse;fg=red> WHOOPS-IE-TOOTLES </> 😳 \n");
64+
$this->line("<fg=red;options=bold>Class already exists:</> {$this->getClassSourcePath()}");
65+
66+
return false;
67+
}
68+
69+
$this->ensureDirectoryExists($classFile);
70+
71+
File::put($classFile, $this->getClassContents());
72+
73+
return $this->component->class;
74+
}
75+
76+
protected function createView()
77+
{
78+
if ($this->isInline()) {
79+
return false;
80+
}
81+
82+
$viewFile = $this->component->view->file;
83+
84+
if (File::exists($viewFile) && ! $this->isForce()) {
85+
$this->line("<fg=red;options=bold>View already exists:</> {$this->getViewSourcePath()}");
86+
87+
return false;
88+
}
89+
90+
$this->ensureDirectoryExists($viewFile);
91+
92+
File::put($viewFile, $this->getViewContents());
93+
94+
return $this->component->view;
95+
}
96+
}

Diff for: src/Commands/stubs/livewire.inline.stub

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace [namespace];
4+
5+
use Livewire\Component;
6+
7+
class [class] extends Component
8+
{
9+
public function render()
10+
{
11+
return <<<'blade'
12+
<div>
13+
<h3>[quote]</h3>
14+
</div>
15+
blade;
16+
}
17+
}

0 commit comments

Comments
 (0)