@@ -46,45 +46,45 @@ discard block |
||
| 46 | 46 | $morphTables = $this->uniqueArray($this->getTables($nodes, 'morphTables')); |
| 47 | 47 | |
| 48 | 48 | if (! $this->option('skip-check')) { |
| 49 | - $this->info('Checking Relationships...'); |
|
| 50 | - $keys = array_keys($nodes); |
|
| 51 | - foreach ($nodes as $model => $i) { |
|
| 52 | - $this->checkRelations($i['belongsTo'], 'belongsTo', $i['filename'], $i['uniquename'], $keys); |
|
| 53 | - // $this->checkRelations($i['hasManyThrough'], 'hasManyThrough', $file, $model); |
|
| 54 | - } |
|
| 55 | - $this->checkPivotRelations($nodes, $pivotTables, 'pivot'); |
|
| 56 | - $this->checkPivotRelations($nodes, $morphTables, 'morph'); |
|
| 49 | + $this->info('Checking Relationships...'); |
|
| 50 | + $keys = array_keys($nodes); |
|
| 51 | + foreach ($nodes as $model => $i) { |
|
| 52 | + $this->checkRelations($i['belongsTo'], 'belongsTo', $i['filename'], $i['uniquename'], $keys); |
|
| 53 | + // $this->checkRelations($i['hasManyThrough'], 'hasManyThrough', $file, $model); |
|
| 54 | + } |
|
| 55 | + $this->checkPivotRelations($nodes, $pivotTables, 'pivot'); |
|
| 56 | + $this->checkPivotRelations($nodes, $morphTables, 'morph'); |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | if ($this->checkedErrors > 0) { |
| 60 | - $this->line(''); |
|
| 61 | - if ($this->option('check-only')) { |
|
| 62 | - $this->info('Checking only, we have found ' . $this->checkedErrors . ' errors.'); |
|
| 63 | - } |
|
| 64 | - $this->printErrors(); |
|
| 60 | + $this->line(''); |
|
| 61 | + if ($this->option('check-only')) { |
|
| 62 | + $this->info('Checking only, we have found ' . $this->checkedErrors . ' errors.'); |
|
| 63 | + } |
|
| 64 | + $this->printErrors(); |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | $proceed = (! $this->option('check-only') && $this->checkedErrors == 0) || $this->option('skip-check'); |
| 68 | 68 | if (! $this->option('check-only') && $this->checkedErrors > 0) { |
| 69 | - $this->line(''); |
|
| 70 | - $proceed = $this->confirm("We have found " . $this->checkedErrors . " errors. Are you sure you want to continue?"); |
|
| 69 | + $this->line(''); |
|
| 70 | + $proceed = $this->confirm("We have found " . $this->checkedErrors . " errors. Are you sure you want to continue?"); |
|
| 71 | 71 | } |
| 72 | 72 | if ($proceed) { |
| 73 | - $this->buildResources($nodes); |
|
| 73 | + $this->buildResources($nodes); |
|
| 74 | 74 | |
| 75 | - // if (!$this->option('no-migration')) { |
|
| 76 | - // $this->call('migrate'); // actually needed for pivot seeders ! |
|
| 77 | - // } |
|
| 75 | + // if (!$this->option('no-migration')) { |
|
| 76 | + // $this->call('migrate'); // actually needed for pivot seeders ! |
|
| 77 | + // } |
|
| 78 | 78 | |
| 79 | - $this->line(''); |
|
| 79 | + $this->line(''); |
|
| 80 | 80 | $this->buildTables('Pivot-Table', 'wn:pivot-table', 'model1', 'model2', $pivotTables); |
| 81 | 81 | |
| 82 | - $this->line(''); |
|
| 82 | + $this->line(''); |
|
| 83 | 83 | $this->buildTables('Morph-Table', 'wn:morph-table', 'model', 'morphable', $morphTables); |
| 84 | 84 | |
| 85 | - if (!$this->option('no-migration')) { |
|
| 86 | - $this->call('migrate'); |
|
| 87 | - } |
|
| 85 | + if (!$this->option('no-migration')) { |
|
| 86 | + $this->call('migrate'); |
|
| 87 | + } |
|
| 88 | 88 | } |
| 89 | 89 | } |
| 90 | 90 | |
@@ -371,10 +371,10 @@ discard block |
||
| 371 | 371 | $deps = $this->getArgumentParser('relations')->parse($nodes[$key]['belongsTo']); |
| 372 | 372 | foreach($deps as $dependency) { |
| 373 | 373 | if(! $dependency['model']){ |
| 374 | - $dependency['model'] = $dependency['name']; |
|
| 375 | - } else if(strpos($dependency['model'], '\\') !== false ){ |
|
| 376 | - $dependency['model'] = substr($dependency['model'], strpos($dependency['model'], '\\')+1); // Cut offs first namespace part |
|
| 377 | - } |
|
| 374 | + $dependency['model'] = $dependency['name']; |
|
| 375 | + } else if(strpos($dependency['model'], '\\') !== false ){ |
|
| 376 | + $dependency['model'] = substr($dependency['model'], strpos($dependency['model'], '\\')+1); // Cut offs first namespace part |
|
| 377 | + } |
|
| 378 | 378 | $dependency['model'] = studly_case(str_singular($dependency['model'])); |
| 379 | 379 | if ($dependency['model'] != $key) { |
| 380 | 380 | $tmp = $this->getDependencies($nodes, $dependency['model'], $seen); |
@@ -3,7 +3,7 @@ discard block |
||
| 3 | 3 | |
| 4 | 4 | class ModelCommand extends BaseCommand { |
| 5 | 5 | |
| 6 | - protected $signature = 'wn:model |
|
| 6 | + protected $signature = 'wn:model |
|
| 7 | 7 | {name : Name of the model.} |
| 8 | 8 | {--fillable= : the fillable fields.} |
| 9 | 9 | {--dates= : date fields.} |
@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | {--force= : override the existing files} |
| 25 | 25 | '; |
| 26 | 26 | |
| 27 | - protected $description = 'Generates a model class for a RESTfull resource'; |
|
| 27 | + protected $description = 'Generates a model class for a RESTfull resource'; |
|
| 28 | 28 | |
| 29 | 29 | public function handle() |
| 30 | 30 | { |
@@ -49,9 +49,9 @@ discard block |
||
| 49 | 49 | |
| 50 | 50 | protected function getAsArrayFields($arg, $isOption = true) |
| 51 | 51 | { |
| 52 | - $arg = ($isOption) ? $this->option($arg) : $this->argument($arg); |
|
| 52 | + $arg = ($isOption) ? $this->option($arg) : $this->argument($arg); |
|
| 53 | 53 | if(is_string($arg)){ |
| 54 | - $arg = explode(',', $arg); |
|
| 54 | + $arg = explode(',', $arg); |
|
| 55 | 55 | } else if(! is_array($arg)) { |
| 56 | 56 | $arg = []; |
| 57 | 57 | } |
@@ -93,32 +93,32 @@ discard block |
||
| 93 | 93 | $template = $this->getTemplate($template); |
| 94 | 94 | foreach ($items as $item) { |
| 95 | 95 | $item['type'] = $type; |
| 96 | - if ($parser == 'relations') { |
|
| 97 | - $item['model'] = $this->prependNamespace($item['model'] ?: $item['name']); |
|
| 98 | - } else if ($parser != 'relations') { |
|
| 99 | - switch($type) { |
|
| 100 | - case "hasManyThrough": |
|
| 101 | - if(! $item['through'] && $item['model']){ |
|
| 102 | - $item['through'] = $this->prependNamespace($item['model']); |
|
| 103 | - $item['model'] = $this->prependNamespace($item['name']); |
|
| 104 | - } else { |
|
| 105 | - $item['through'] = $this->prependNamespace($item['through']); |
|
| 106 | - $item['model'] = $this->prependNamespace($item['model']); |
|
| 107 | - } |
|
| 108 | - break; |
|
| 109 | - case "morphMany": |
|
| 110 | - case "morphToMany": |
|
| 111 | - case "morphedByMany": |
|
| 112 | - if(! $item['through']){ |
|
| 113 | - $item['through'] = $item['model']; |
|
| 114 | - $item['model'] = $this->prependNamespace($item['name']); |
|
| 115 | - } else { |
|
| 116 | - $item['model'] = $this->prependNamespace($item['model']); |
|
| 117 | - } |
|
| 118 | - break; |
|
| 119 | - |
|
| 120 | - } |
|
| 121 | - } |
|
| 96 | + if ($parser == 'relations') { |
|
| 97 | + $item['model'] = $this->prependNamespace($item['model'] ?: $item['name']); |
|
| 98 | + } else if ($parser != 'relations') { |
|
| 99 | + switch($type) { |
|
| 100 | + case "hasManyThrough": |
|
| 101 | + if(! $item['through'] && $item['model']){ |
|
| 102 | + $item['through'] = $this->prependNamespace($item['model']); |
|
| 103 | + $item['model'] = $this->prependNamespace($item['name']); |
|
| 104 | + } else { |
|
| 105 | + $item['through'] = $this->prependNamespace($item['through']); |
|
| 106 | + $item['model'] = $this->prependNamespace($item['model']); |
|
| 107 | + } |
|
| 108 | + break; |
|
| 109 | + case "morphMany": |
|
| 110 | + case "morphToMany": |
|
| 111 | + case "morphedByMany": |
|
| 112 | + if(! $item['through']){ |
|
| 113 | + $item['through'] = $item['model']; |
|
| 114 | + $item['model'] = $this->prependNamespace($item['name']); |
|
| 115 | + } else { |
|
| 116 | + $item['model'] = $this->prependNamespace($item['model']); |
|
| 117 | + } |
|
| 118 | + break; |
|
| 119 | + |
|
| 120 | + } |
|
| 121 | + } |
|
| 122 | 122 | $relations[] = $template->with($item)->get(); |
| 123 | 123 | } |
| 124 | 124 | } |
@@ -128,9 +128,9 @@ discard block |
||
| 128 | 128 | protected function getRules() |
| 129 | 129 | { |
| 130 | 130 | $items = $this->parseValue($this->option('rules'), 'rules'); |
| 131 | - if ($items === false) { |
|
| 132 | - return $this->spaces(8) . "// Validation rules"; |
|
| 133 | - } |
|
| 131 | + if ($items === false) { |
|
| 132 | + return $this->spaces(8) . "// Validation rules"; |
|
| 133 | + } |
|
| 134 | 134 | |
| 135 | 135 | $template = $this->getTemplate('model/rule'); |
| 136 | 136 | $rules = []; |
@@ -10,10 +10,10 @@ discard block |
||
| 10 | 10 | class BaseCommand extends Command { |
| 11 | 11 | |
| 12 | 12 | protected $fs; |
| 13 | - protected $templates; |
|
| 13 | + protected $templates; |
|
| 14 | 14 | |
| 15 | - public function __construct(Filesystem $fs) |
|
| 16 | - { |
|
| 15 | + public function __construct(Filesystem $fs) |
|
| 16 | + { |
|
| 17 | 17 | parent::__construct(); |
| 18 | 18 | |
| 19 | 19 | $this->fs = $fs; |
@@ -56,11 +56,11 @@ discard block |
||
| 56 | 56 | |
| 57 | 57 | protected function getNamespace(string $path = null): string |
| 58 | 58 | { |
| 59 | - if (empty($path)) { |
|
| 60 | - $path = $this->option('path'); |
|
| 61 | - } |
|
| 59 | + if (empty($path)) { |
|
| 60 | + $path = $this->option('path'); |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - return implode('\\', array_map('studly_case', array_filter(array_map('trim', explode('/', $path)), function($value) { |
|
| 63 | + return implode('\\', array_map('studly_case', array_filter(array_map('trim', explode('/', $path)), function($value) { |
|
| 64 | 64 | return !empty($value); |
| 65 | 65 | }))); |
| 66 | 66 | } |