1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace EasyPanel\Commands; |
4
|
|
|
|
5
|
|
|
use Illuminate\Console\Command; |
6
|
|
|
use Symfony\Component\Console\Exception\CommandNotFoundException; |
7
|
|
|
|
8
|
|
|
class MakeCRUD extends Command |
9
|
|
|
{ |
10
|
|
|
|
11
|
|
|
protected $signature = 'panel:crud {name?} {--f|force : Force mode}'; |
12
|
|
|
|
13
|
|
|
protected $description = 'Create all action for CRUDs'; |
14
|
|
|
|
15
|
|
|
public function handle() |
16
|
|
|
{ |
17
|
|
|
$names = $this->argument('name') ? [$this->argument('name')] : config('easy_panel.actions', []); |
18
|
|
|
if($names == null) { |
19
|
|
|
throw new CommandNotFoundException("There is no action in config file"); |
20
|
|
|
} |
21
|
|
|
foreach ($names as $name) { |
22
|
|
|
$config = config('easy_panel.crud.' . $name); |
23
|
|
|
if (!$config) { |
24
|
|
|
throw new CommandNotFoundException("There is no {$name} in config file"); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
$this->modelNameIsCorrect($name, $config['model']); |
28
|
|
|
|
29
|
|
|
if (!$config['create']) { |
30
|
|
|
$this->warn("The create action is disabled for {$name}"); |
31
|
|
|
} else { |
32
|
|
|
$this->call('panel:create', ['name' => $name, '--force' => $this->option('force')]); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
if (!$config['update']) { |
36
|
|
|
$this->warn("The update action is disabled for {$name}"); |
37
|
|
|
} else { |
38
|
|
|
$this->call('panel:update', ['name' => $name, '--force' => $this->option('force')]); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
$this->call('panel:read', ['name' => $name, '--force' => $this->option('force')]); |
42
|
|
|
} |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
private function modelNameIsCorrect($name, $model) |
46
|
|
|
{ |
47
|
|
|
$model = explode('\\', $model); |
48
|
|
|
$model = strtolower(end($model)); |
49
|
|
|
|
50
|
|
|
if($model != $name){ |
51
|
|
|
throw new CommandNotFoundException("Action key should be equal to model name, You are using {$name} as key name but your model name is {$model}"); |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
} |
56
|
|
|
|