Skip to content

Commit ae4975e

Browse files
committed
Formatting
1 parent 48c5d5f commit ae4975e

File tree

4 files changed

+80
-26
lines changed

4 files changed

+80
-26
lines changed

CHANGELOG.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ All notable changes to `laravel-livewire-tables` will be documented in this file
44

55
## [Unreleased]
66

7+
## [1.12.0] - 2021-07-31
8+
9+
### Added
10+
11+
- [Make datatable command](https://github.com/rappasoft/laravel-livewire-tables/pull/408)
12+
713
## [1.11.0] - 2021-07-10
814

915
### Added
@@ -428,7 +434,8 @@ All notable changes to `laravel-livewire-tables` will be documented in this file
428434

429435
- Initial release
430436

431-
[Unreleased]: https://github.com/rappasoft/laravel-livewire-tables/compare/v1.11.0...development
437+
[Unreleased]: https://github.com/rappasoft/laravel-livewire-tables/compare/v1.12.0...development
438+
[1.12.0]: https://github.com/rappasoft/laravel-livewire-tables/compare/v1.11.0...v1.12.0
432439
[1.11.0]: https://github.com/rappasoft/laravel-livewire-tables/compare/v1.10.4...v1.11.0
433440
[1.10.4]: https://github.com/rappasoft/laravel-livewire-tables/compare/v1.10.3...v1.10.4
434441
[1.10.3]: https://github.com/rappasoft/laravel-livewire-tables/compare/v1.10.2...v1.10.3

src/Commands/MakeCommand.php

Lines changed: 64 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,48 @@
88
use Livewire\Commands\ComponentParser;
99
use Livewire\Commands\MakeCommand as LivewireMakeCommand;
1010

11+
/**
12+
* Class MakeCommand
13+
*
14+
* @package Rappasoft\LaravelLivewireTables\Commands
15+
*/
1116
class MakeCommand extends Command
1217
{
18+
19+
/**
20+
* @var
21+
*/
1322
protected $parser;
14-
protected $model = null;
15-
protected $viewPath = null;
23+
24+
/**
25+
* @var
26+
*/
27+
protected $model;
28+
29+
/**
30+
* @var
31+
*/
32+
protected $viewPath;
33+
1634
/**
1735
* The name and signature of the console command.
1836
*
1937
* @var string
2038
*/
21-
protected $signature = 'make:table
39+
protected $signature = 'make:datatable
2240
{name : The name of your Livewire class}
23-
{model? : The name of the model you want to use in this table }
41+
{model? : The name of the model you want to use in this table}
2442
{--view : We will generate a row view for you}
25-
{--force }';
43+
{--force}';
2644

2745
/**
2846
* The console command description.
2947
*
3048
* @var string
3149
*/
32-
protected $description = 'Generate a Laravel Livewire table class and view';
50+
protected $description = 'Generate a Laravel Livewire datatable class and view';
3351

34-
public function handle()
52+
public function handle(): void
3553
{
3654
$this->parser = new ComponentParser(
3755
config('livewire.class_namespace'),
@@ -42,7 +60,6 @@ public function handle()
4260
$livewireMakeCommand = new LivewireMakeCommand();
4361

4462
if($livewireMakeCommand->isReservedClassName($name = $this->parser->className())) {
45-
$this->line("<options=bold,reverse;fg=red> WHOOPS! </> 😳 \n");
4663
$this->line("<fg=red;options=bold>Class is reserved:</> {$name}");
4764
return;
4865
}
@@ -56,12 +73,16 @@ public function handle()
5673
$this->info('Livewire Datatable Created: ' . $this->parser->className());
5774
}
5875

59-
protected function createClass($force = false)
76+
/**
77+
* @param false $force
78+
*
79+
* @return false
80+
*/
81+
protected function createClass(bool $force = false)
6082
{
6183
$classPath = $this->parser->classPath();
6284

63-
if (File::exists($classPath) && ! $force) {
64-
$this->line("<options=bold,reverse;fg=red> WHOOPS-IE-TOOTLES </> 😳 \n");
85+
if (! $force && File::exists($classPath)) {
6586
$this->line("<fg=red;options=bold>Class already exists:</> {$this->parser->relativeClassPath()}");
6687

6788
return false;
@@ -74,14 +95,20 @@ protected function createClass($force = false)
7495
return $classPath;
7596
}
7697

98+
/**
99+
* @param false $force
100+
*
101+
* @return false|string|null
102+
*/
77103
protected function createView($force = false)
78104
{
79105
if(! $this->option('view')) {
80106
return null;
81107
}
108+
82109
$viewPath = base_path('resources/views/livewire-tables/rows/' . Str::snake($this->parser->className()->__toString()) . '.blade.php');
83-
if (File::exists($viewPath) && ! $force) {
84-
$this->line("<options=bold,reverse;fg=red> WHOOPS-IE-TOOTLES </> 😳 \n");
110+
111+
if (! $force && File::exists($viewPath)) {
85112
$this->line("<fg=red;options=bold>View already exists:</> {$viewPath}");
86113

87114
return false;
@@ -94,14 +121,20 @@ protected function createView($force = false)
94121
return $viewPath;
95122
}
96123

97-
protected function ensureDirectoryExists($path)
124+
/**
125+
* @param $path
126+
*/
127+
protected function ensureDirectoryExists($path): void
98128
{
99129
if (! File::isDirectory(dirname($path))) {
100-
File::makeDirectory(dirname($path), 0777, $recursive = true, $force = true);
130+
File::makeDirectory(dirname($path), 0777, true, true);
101131
}
102132
}
103133

104-
public function classContents()
134+
/**
135+
* @return string
136+
*/
137+
public function classContents(): string
105138
{
106139
if($this->model) {
107140
$template = file_get_contents(__DIR__.DIRECTORY_SEPARATOR.'table-with-model.stub');
@@ -134,25 +167,37 @@ public function rowView(): string
134167
return $contents;
135168
}
136169

170+
/**
171+
* @return string
172+
*/
137173
private function getViewPathForRowView(): string
138174
{
139-
return Str::before(Str::after($this->viewPath, 'resources/views/'), '.blade.php');
175+
return Str::replace('/', '.', Str::before(Str::after($this->viewPath, 'resources/views/'), '.blade.php'));
140176
}
141177

178+
/**
179+
* @return false|string
180+
*/
142181
public function viewContents()
143182
{
144183
return file_get_contents(__DIR__.DIRECTORY_SEPARATOR.'view.stub');
145184
}
146185

147-
public function getModelImport()
186+
/**
187+
* @return string
188+
*/
189+
public function getModelImport(): string
148190
{
149191
if(File::exists(app_path('Models/' . $this->model . '.php'))) {
150192
return 'App\Models\\' . $this->model;
151193
}
194+
152195
if(File::exists(app_path($this->model . '.php'))) {
153196
return 'App\\' . $this->model;
154197
}
155-
$this->error('Could not find path to model');
198+
199+
$this->error('Could not find path to model.');
200+
156201
return 'App\Models\\' . $this->model;
157202
}
158203
}

src/Commands/view.stub

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<x-livewire-tables::table.cell>
2-
{{-- Note: This is a tailwind cell --}}
3-
{{-- For bootstrap 4, use <x-livewire-tables::bs4.table.cell> --}}
4-
{{-- For bootstrap 5, use <x-livewire-tables::bs5.table.cell> --}}
2+
{{-- Note: This is a tailwind cell --}}
3+
{{-- For bootstrap 4, use <x-livewire-tables::bs4.table.cell> --}}
4+
{{-- For bootstrap 5, use <x-livewire-tables::bs5.table.cell> --}}
55
</x-livewire-tables::table.cell>

src/LaravelLivewireTablesServiceProvider.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,14 @@ public function bootingPackage(): void
3737
$this->registerCommands();
3838
}
3939

40-
protected function registerCommands()
40+
protected function registerCommands(): void
4141
{
42-
if (! $this->app->runningInConsole()) return;
42+
if (! $this->app->runningInConsole()) {
43+
return;
44+
}
4345

4446
$this->commands([
45-
MakeCommand::class, // make:table
47+
MakeCommand::class,
4648
]);
4749
}
4850

0 commit comments

Comments
 (0)