1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Microboard\Commands; |
4
|
|
|
|
5
|
|
|
use Illuminate\Foundation\Console\RequestMakeCommand; |
6
|
|
|
use Illuminate\Support\Str; |
7
|
|
|
use Microboard\Foundations\Traits\MicroboardPathResolver; |
8
|
|
|
use Symfony\Component\Console\Input\InputOption; |
9
|
|
|
|
10
|
|
|
class ResourceRequest extends RequestMakeCommand |
11
|
|
|
{ |
12
|
|
|
use MicroboardPathResolver; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* The console command name. |
16
|
|
|
* |
17
|
|
|
* @var string |
18
|
|
|
*/ |
19
|
|
|
protected $name = 'microboard:request'; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Build the class with the given name. |
23
|
|
|
* |
24
|
|
|
* @param string $name |
25
|
|
|
* @return string |
26
|
|
|
* |
27
|
|
|
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException |
28
|
|
|
*/ |
29
|
|
|
protected function buildClass($name) |
30
|
|
|
{ |
31
|
|
|
$stub = parent::buildClass($name); |
32
|
|
|
|
33
|
|
|
return $this->replaceColumnsAndTranslationsPrefix($stub, $name); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @param $stub |
38
|
|
|
* @param $name |
39
|
|
|
* @return string |
40
|
|
|
*/ |
41
|
|
|
private function replaceColumnsAndTranslationsPrefix(&$stub, $name) |
42
|
|
|
{ |
43
|
|
|
$columns = ''; |
44
|
|
|
|
45
|
|
|
if ($fillables = $this->option('columns')) { |
46
|
|
|
if (! is_array($fillables)) { |
47
|
|
|
$fillables = explode(',', $fillables); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
foreach ($fillables as $column) { |
51
|
|
|
$columns .= "\r\n\t\t\t'{$column}' => ['required', 'string'],"; |
52
|
|
|
} |
53
|
|
|
} else { |
54
|
|
|
$columns = "\r\n\t\t\t//"; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
$stub = str_replace( |
58
|
|
|
['{{ modelName }}', '{{ columns }}'], |
59
|
|
|
[Str::of(class_basename($this->option('model')))->plural()->snake(), $columns], |
60
|
|
|
$stub |
61
|
|
|
); |
62
|
|
|
|
63
|
|
|
return $stub; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Get the stub file for the generator. |
68
|
|
|
* |
69
|
|
|
* @return string |
70
|
|
|
*/ |
71
|
|
|
protected function getStub() |
72
|
|
|
{ |
73
|
|
|
return $this->resolveStubPath('/stubs/request.stub'); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Get the console command arguments. |
78
|
|
|
* |
79
|
|
|
* @return array |
80
|
|
|
*/ |
81
|
|
|
protected function getOptions() |
82
|
|
|
{ |
83
|
|
|
return [ |
84
|
|
|
...$this->pathOptions(), |
|
|
|
|
85
|
|
|
['model', '', InputOption::VALUE_OPTIONAL, ''], |
86
|
|
|
['columns', '', InputOption::VALUE_OPTIONAL, ''] |
87
|
|
|
]; |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|