Skip to content

Commit 60f1caf

Browse files
committed
create filter command updated
1 parent 57f2216 commit 60f1caf

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

src/Commands/MakeFilter.php

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,21 @@
44

55
use Illuminate\Console\Command;
66

7-
class ShowTableColumnsCommand extends Command
7+
class MakeFilter extends Command
88
{
99
/**
1010
* The name and signature of the console command.
1111
*
1212
* @var string
1313
*/
14-
protected $signature = 'make:filter';
14+
protected $signature = 'make:filter {class}';
15+
16+
/**
17+
* The type of class being generated.
18+
*
19+
* @var string
20+
*/
21+
protected $type = 'Filter';
1522

1623
/**
1724
* The console command description.
@@ -37,7 +44,7 @@ public function __construct()
3744
*/
3845
public function handle()
3946
{
40-
$filterClass = $this->option('name');
47+
$filterClass = $this->argument('class');
4148

4249
$filterContent = str_replace(
4350
[
@@ -51,18 +58,24 @@ public function handle()
5158
$this->getStub()
5259
);
5360

61+
$filtersPath = config('eloquent_filters.base_folder', app_path('Filters'));
62+
if (!is_dir($filtersPath)) {
63+
mkdir($filtersPath, 0777, true);
64+
}
65+
5466
file_put_contents(
55-
"$filterClass.php",
56-
config('eloquent_filters.base_folder', app_path('Filters'))
67+
"$filtersPath/$filterClass.php",
68+
$filterContent
5769
);
5870

5971
$this->info('Filter created.');
72+
$this->info('Add trait into your model: "use \LaraToolbox\EloquentFilters\Traits\Filters;"');
6073
return 0;
6174
}
6275

6376
private function getStub()
6477
{
6578
// TODO: make stub customizable
66-
return '<?php'.PHP_EOL.PHP_EOL.file_get_contents('../stub/filter.stub');
79+
return '<?php'.PHP_EOL.PHP_EOL.file_get_contents(dirname(__FILE__).'/../stub/filter.stub');
6780
}
6881
}

0 commit comments

Comments
 (0)