@@ -5,7 +5,7 @@ discard block |
||
| 5 | 5 | |
| 6 | 6 | class RouteCommand extends BaseCommand { |
| 7 | 7 | |
| 8 | - protected $signature = 'wn:route |
|
| 8 | + protected $signature = 'wn:route |
|
| 9 | 9 | {resource : Name of the resource.} |
| 10 | 10 | {--controller= : Name of the RESTful controller.} |
| 11 | 11 | {--controller-namespace= : Namespace of the RESTful controller if not default.} |
@@ -13,22 +13,22 @@ discard block |
||
| 13 | 13 | {--laravel= : Use Laravel style route definitions} |
| 14 | 14 | '; |
| 15 | 15 | |
| 16 | - protected $description = 'Generates RESTful routes.'; |
|
| 16 | + protected $description = 'Generates RESTful routes.'; |
|
| 17 | 17 | |
| 18 | 18 | public function handle() |
| 19 | 19 | { |
| 20 | 20 | $resource = $this->argument('resource'); |
| 21 | 21 | $laravelRoutes = $this->option('laravel'); |
| 22 | - $templateFile = 'routes'; |
|
| 22 | + $templateFile = 'routes'; |
|
| 23 | 23 | $routesPath = $this->option('path') ?: 'routes/web.php'; |
| 24 | 24 | if ($laravelRoutes) { |
| 25 | 25 | $templateFile = 'routes-laravel'; |
| 26 | 26 | $routesPath = $this->option('path') ?: 'routes/api.php'; |
| 27 | - if (!$this->fs->isFile($routesPath)) { |
|
| 28 | - if (!$this->fs->isDirectory(\dirname($routesPath))) { |
|
| 29 | - $this->fs->makeDirectory(\dirname($routesPath)); |
|
| 30 | - } |
|
| 31 | - $this->fs->put($routesPath, " |
|
| 27 | + if (!$this->fs->isFile($routesPath)) { |
|
| 28 | + if (!$this->fs->isDirectory(\dirname($routesPath))) { |
|
| 29 | + $this->fs->makeDirectory(\dirname($routesPath)); |
|
| 30 | + } |
|
| 31 | + $this->fs->put($routesPath, " |
|
| 32 | 32 | <?php |
| 33 | 33 | |
| 34 | 34 | use Illuminate\Http\Request; |
@@ -49,11 +49,11 @@ discard block |
||
| 49 | 49 | }); |
| 50 | 50 | |
| 51 | 51 | "); |
| 52 | - } |
|
| 52 | + } |
|
| 53 | + } |
|
| 54 | + if ($this->option('controller-namespace')) { |
|
| 55 | + $templateFile .= '-namespace'; |
|
| 53 | 56 | } |
| 54 | - if ($this->option('controller-namespace')) { |
|
| 55 | - $templateFile .= '-namespace'; |
|
| 56 | - } |
|
| 57 | 57 | |
| 58 | 58 | if (!$this->fs->isFile($routesPath)) { |
| 59 | 59 | $routesPath = 'app/Http/routes.php'; |
@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | ->with([ |
| 65 | 65 | 'resource' => $resource, |
| 66 | 66 | 'controller' => $this->getController(), |
| 67 | - 'namespace' => $this->option('controller-namespace'), |
|
| 67 | + 'namespace' => $this->option('controller-namespace'), |
|
| 68 | 68 | ]) |
| 69 | 69 | ->get(); |
| 70 | 70 | $this->save($content, $routesPath, "{$resource} routes", true); |
@@ -36,32 +36,32 @@ discard block |
||
| 36 | 36 | $files = $this->argument('files'); |
| 37 | 37 | $this->nodes = []; |
| 38 | 38 | foreach ($files as $file) { |
| 39 | - $this->info("Reading file ".$file); |
|
| 39 | + $this->info("Reading file ".$file); |
|
| 40 | 40 | |
| 41 | - $content = $this->fs->get($file); |
|
| 42 | - $content = Yaml::parse($content); |
|
| 41 | + $content = $this->fs->get($file); |
|
| 42 | + $content = Yaml::parse($content); |
|
| 43 | 43 | |
| 44 | - foreach ($content as $model => $i){ |
|
| 45 | - /* |
|
| 44 | + foreach ($content as $model => $i){ |
|
| 45 | + /* |
|
| 46 | 46 | $i['modelname'] = as originally in YAML defined |
| 47 | 47 | $i['name'] = as originally defined in snake_case |
| 48 | 48 | $i['uniquename']= for key in singular studly_case |
| 49 | 49 | */ |
| 50 | - $i['filename'] = $file; |
|
| 51 | - $i['modelname'] = $model; |
|
| 52 | - $model = studly_case(str_singular($model)); |
|
| 53 | - $i['uniquename'] = $model; |
|
| 54 | - |
|
| 55 | - if (empty($this->nodes[$model]) || $this->option('force-redefine')) { |
|
| 56 | - if (!empty($this->nodes[$model])) { |
|
| 57 | - $this->checkError($model . ": forced to redefine (in file " . $this->nodes[$model]['filename'] . ", redefined from file ".$file.")"); |
|
| 58 | - } |
|
| 59 | - $i = $this->getResourceParams($i); |
|
| 60 | - $this->nodes[$model] = $i; |
|
| 61 | - } else { |
|
| 62 | - $this->checkError($model . ": already defined (in file " . $this->nodes[$model]['filename'] . ", trying to redefine from file ".$file."; Use --force-redefine to force redefinition)"); |
|
| 63 | - } |
|
| 64 | - } |
|
| 50 | + $i['filename'] = $file; |
|
| 51 | + $i['modelname'] = $model; |
|
| 52 | + $model = studly_case(str_singular($model)); |
|
| 53 | + $i['uniquename'] = $model; |
|
| 54 | + |
|
| 55 | + if (empty($this->nodes[$model]) || $this->option('force-redefine')) { |
|
| 56 | + if (!empty($this->nodes[$model])) { |
|
| 57 | + $this->checkError($model . ": forced to redefine (in file " . $this->nodes[$model]['filename'] . ", redefined from file ".$file.")"); |
|
| 58 | + } |
|
| 59 | + $i = $this->getResourceParams($i); |
|
| 60 | + $this->nodes[$model] = $i; |
|
| 61 | + } else { |
|
| 62 | + $this->checkError($model . ": already defined (in file " . $this->nodes[$model]['filename'] . ", trying to redefine from file ".$file."; Use --force-redefine to force redefinition)"); |
|
| 63 | + } |
|
| 64 | + } |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | $this->line(''); |
@@ -70,123 +70,123 @@ discard block |
||
| 70 | 70 | $this->nodes = $this->sortDependencies(); |
| 71 | 71 | |
| 72 | 72 | if (! $this->option('skip-check')) { |
| 73 | - $this->info('Checking Relationships...'); |
|
| 74 | - $keys = array_keys($this->nodes); |
|
| 75 | - foreach ($this->nodes as $model => $i) { |
|
| 76 | - $this->checkRelations($i['belongsTo'], 'belongsTo', $i['filename'], $i['uniquename'], $keys); |
|
| 77 | - // $this->checkRelations($i['hasManyThrough'], 'hasManyThrough', $file, $model); |
|
| 78 | - } |
|
| 79 | - $this->checkPivotRelations($this->pivotTables, 'pivot'); |
|
| 80 | - $this->checkPivotRelations($this->morphTables, 'morph'); |
|
| 73 | + $this->info('Checking Relationships...'); |
|
| 74 | + $keys = array_keys($this->nodes); |
|
| 75 | + foreach ($this->nodes as $model => $i) { |
|
| 76 | + $this->checkRelations($i['belongsTo'], 'belongsTo', $i['filename'], $i['uniquename'], $keys); |
|
| 77 | + // $this->checkRelations($i['hasManyThrough'], 'hasManyThrough', $file, $model); |
|
| 78 | + } |
|
| 79 | + $this->checkPivotRelations($this->pivotTables, 'pivot'); |
|
| 80 | + $this->checkPivotRelations($this->morphTables, 'morph'); |
|
| 81 | 81 | } |
| 82 | 82 | |
| 83 | 83 | if ($this->checkedErrors > 0) { |
| 84 | - $this->line(''); |
|
| 85 | - if ($this->option('check-only')) { |
|
| 86 | - $this->info('Checking only, we have found ' . $this->checkedErrors . ' errors.'); |
|
| 87 | - } |
|
| 88 | - $this->printErrors(); |
|
| 84 | + $this->line(''); |
|
| 85 | + if ($this->option('check-only')) { |
|
| 86 | + $this->info('Checking only, we have found ' . $this->checkedErrors . ' errors.'); |
|
| 87 | + } |
|
| 88 | + $this->printErrors(); |
|
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | $proceed = (! $this->option('check-only') && $this->checkedErrors == 0) || $this->option('skip-check'); |
| 92 | 92 | if (! $this->option('check-only') && $this->checkedErrors > 0) { |
| 93 | - $this->line(''); |
|
| 94 | - $proceed = $this->confirm("We have found " . $this->checkedErrors . " errors. Are you sure you want to continue?"); |
|
| 93 | + $this->line(''); |
|
| 94 | + $proceed = $this->confirm("We have found " . $this->checkedErrors . " errors. Are you sure you want to continue?"); |
|
| 95 | 95 | } |
| 96 | 96 | if ($proceed) { |
| 97 | - $modelIndex = 0; |
|
| 97 | + $modelIndex = 0; |
|
| 98 | 98 | $migrationIdLength = strlen((string)count($this->nodes)); |
| 99 | - foreach ($this->nodes as $i) { |
|
| 100 | - $migrationName = 'Create' . ucwords(str_plural($i['name'])); |
|
| 101 | - $migrationFile = date('Y_m_d_His') . '-' . str_pad($modelIndex , $migrationIdLength, 0, STR_PAD_LEFT) . '_' . snake_case($migrationName) . '_table'; |
|
| 102 | - |
|
| 103 | - $this->line(''); |
|
| 104 | - $this->info('Building Model ' . $i['uniquename']); |
|
| 105 | - |
|
| 106 | - $options = [ |
|
| 107 | - 'name' => $i['name'], |
|
| 108 | - 'fields' => $i['fields'], |
|
| 109 | - '--add' => $i['add'], |
|
| 110 | - '--has-many' => $i['hasMany'], |
|
| 111 | - '--has-one' => $i['hasOne'], |
|
| 112 | - '--belongs-to' => $i['belongsTo'], |
|
| 113 | - '--belongs-to-many' => $i['belongsToMany'], |
|
| 114 | - '--has-many-through' => $i['hasManyThrough'], |
|
| 115 | - '--morph-to' => $i['morphTo'], |
|
| 116 | - '--morph-many' => $i['morphMany'], |
|
| 117 | - '--morph-to-many' => $i['morphToMany'], |
|
| 118 | - '--morphed-by-many' => $i['morphedByMany'], |
|
| 119 | - '--no-routes' => $this->option('no-routes'), |
|
| 120 | - '--no-controller' => $this->option('no-controllers'), |
|
| 121 | - '--force' => $this->option('force'), |
|
| 122 | - '--migration-file' => $migrationFile, |
|
| 123 | - ]; |
|
| 124 | - if ($this->option('laravel')) { |
|
| 125 | - $options['--laravel'] = true; |
|
| 126 | - } |
|
| 127 | - if ($this->option('routes')) { |
|
| 128 | - $options['--routes'] = $this->option('routes'); |
|
| 129 | - } |
|
| 130 | - if ($this->option('controllers')) { |
|
| 131 | - $options['--controller'] = $this->option('controllers'); |
|
| 132 | - } |
|
| 133 | - if ($this->option('path')) { |
|
| 134 | - $options['--path'] = $this->option('path'); |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - $this->call('wn:resource', $options); |
|
| 138 | - $modelIndex++; |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - // if (!$this->option('no-migration')) { |
|
| 142 | - // $this->call('migrate'); // actually needed for pivot seeders ! |
|
| 143 | - // } |
|
| 144 | - |
|
| 145 | - $this->pivotTables = array_map( |
|
| 146 | - 'unserialize', |
|
| 147 | - array_unique(array_map('serialize', $this->pivotTables)) |
|
| 148 | - ); |
|
| 149 | - |
|
| 150 | - $this->line(''); |
|
| 151 | - foreach ($this->pivotTables as $tables) { |
|
| 152 | - $this->info('Building Pivot-Table ' . $tables[0] . ' - ' . $tables[1]); |
|
| 153 | - $this->call('wn:pivot-table', [ |
|
| 154 | - 'model1' => $tables[0], |
|
| 155 | - 'model2' => $tables[1], |
|
| 156 | - '--force' => $this->option('force') |
|
| 157 | - ]); |
|
| 158 | - |
|
| 159 | - // $this->call('wn:pivot-seeder', [ |
|
| 160 | - // 'model1' => $tables[0], |
|
| 161 | - // 'model2' => $tables[1], |
|
| 162 | - // '--force' => $this->option('force') |
|
| 163 | - // ]); |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - $this->morphTables = array_map( |
|
| 167 | - 'unserialize', |
|
| 168 | - array_unique(array_map('serialize', $this->morphTables)) |
|
| 169 | - ); |
|
| 170 | - |
|
| 171 | - $this->line(''); |
|
| 172 | - foreach ($this->morphTables as $tables) { |
|
| 173 | - $this->info('Building Morph-Table ' . $tables[0] . ' - ' . $tables[1]); |
|
| 174 | - $this->call('wn:morph-table', [ |
|
| 175 | - 'model' => $tables[0], |
|
| 176 | - 'morphable' => $tables[1], |
|
| 177 | - '--force' => $this->option('force') |
|
| 178 | - ]); |
|
| 179 | - |
|
| 180 | - // $this->call('wn:pivot-seeder', [ |
|
| 181 | - // 'model1' => $tables[0], |
|
| 182 | - // 'model2' => $tables[1], |
|
| 183 | - // '--force' => $this->option('force') |
|
| 184 | - // ]); |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - if (!$this->option('no-migration')) { |
|
| 188 | - $this->call('migrate'); |
|
| 189 | - } |
|
| 99 | + foreach ($this->nodes as $i) { |
|
| 100 | + $migrationName = 'Create' . ucwords(str_plural($i['name'])); |
|
| 101 | + $migrationFile = date('Y_m_d_His') . '-' . str_pad($modelIndex , $migrationIdLength, 0, STR_PAD_LEFT) . '_' . snake_case($migrationName) . '_table'; |
|
| 102 | + |
|
| 103 | + $this->line(''); |
|
| 104 | + $this->info('Building Model ' . $i['uniquename']); |
|
| 105 | + |
|
| 106 | + $options = [ |
|
| 107 | + 'name' => $i['name'], |
|
| 108 | + 'fields' => $i['fields'], |
|
| 109 | + '--add' => $i['add'], |
|
| 110 | + '--has-many' => $i['hasMany'], |
|
| 111 | + '--has-one' => $i['hasOne'], |
|
| 112 | + '--belongs-to' => $i['belongsTo'], |
|
| 113 | + '--belongs-to-many' => $i['belongsToMany'], |
|
| 114 | + '--has-many-through' => $i['hasManyThrough'], |
|
| 115 | + '--morph-to' => $i['morphTo'], |
|
| 116 | + '--morph-many' => $i['morphMany'], |
|
| 117 | + '--morph-to-many' => $i['morphToMany'], |
|
| 118 | + '--morphed-by-many' => $i['morphedByMany'], |
|
| 119 | + '--no-routes' => $this->option('no-routes'), |
|
| 120 | + '--no-controller' => $this->option('no-controllers'), |
|
| 121 | + '--force' => $this->option('force'), |
|
| 122 | + '--migration-file' => $migrationFile, |
|
| 123 | + ]; |
|
| 124 | + if ($this->option('laravel')) { |
|
| 125 | + $options['--laravel'] = true; |
|
| 126 | + } |
|
| 127 | + if ($this->option('routes')) { |
|
| 128 | + $options['--routes'] = $this->option('routes'); |
|
| 129 | + } |
|
| 130 | + if ($this->option('controllers')) { |
|
| 131 | + $options['--controller'] = $this->option('controllers'); |
|
| 132 | + } |
|
| 133 | + if ($this->option('path')) { |
|
| 134 | + $options['--path'] = $this->option('path'); |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + $this->call('wn:resource', $options); |
|
| 138 | + $modelIndex++; |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + // if (!$this->option('no-migration')) { |
|
| 142 | + // $this->call('migrate'); // actually needed for pivot seeders ! |
|
| 143 | + // } |
|
| 144 | + |
|
| 145 | + $this->pivotTables = array_map( |
|
| 146 | + 'unserialize', |
|
| 147 | + array_unique(array_map('serialize', $this->pivotTables)) |
|
| 148 | + ); |
|
| 149 | + |
|
| 150 | + $this->line(''); |
|
| 151 | + foreach ($this->pivotTables as $tables) { |
|
| 152 | + $this->info('Building Pivot-Table ' . $tables[0] . ' - ' . $tables[1]); |
|
| 153 | + $this->call('wn:pivot-table', [ |
|
| 154 | + 'model1' => $tables[0], |
|
| 155 | + 'model2' => $tables[1], |
|
| 156 | + '--force' => $this->option('force') |
|
| 157 | + ]); |
|
| 158 | + |
|
| 159 | + // $this->call('wn:pivot-seeder', [ |
|
| 160 | + // 'model1' => $tables[0], |
|
| 161 | + // 'model2' => $tables[1], |
|
| 162 | + // '--force' => $this->option('force') |
|
| 163 | + // ]); |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + $this->morphTables = array_map( |
|
| 167 | + 'unserialize', |
|
| 168 | + array_unique(array_map('serialize', $this->morphTables)) |
|
| 169 | + ); |
|
| 170 | + |
|
| 171 | + $this->line(''); |
|
| 172 | + foreach ($this->morphTables as $tables) { |
|
| 173 | + $this->info('Building Morph-Table ' . $tables[0] . ' - ' . $tables[1]); |
|
| 174 | + $this->call('wn:morph-table', [ |
|
| 175 | + 'model' => $tables[0], |
|
| 176 | + 'morphable' => $tables[1], |
|
| 177 | + '--force' => $this->option('force') |
|
| 178 | + ]); |
|
| 179 | + |
|
| 180 | + // $this->call('wn:pivot-seeder', [ |
|
| 181 | + // 'model1' => $tables[0], |
|
| 182 | + // 'model2' => $tables[1], |
|
| 183 | + // '--force' => $this->option('force') |
|
| 184 | + // ]); |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + if (!$this->option('no-migration')) { |
|
| 188 | + $this->call('migrate'); |
|
| 189 | + } |
|
| 190 | 190 | } |
| 191 | 191 | } |
| 192 | 192 | |
@@ -328,10 +328,10 @@ discard block |
||
| 328 | 328 | $deps = $this->getArgumentParser('relations')->parse($this->nodes[$key]['belongsTo']); |
| 329 | 329 | foreach($deps as $dependency) { |
| 330 | 330 | if(! $dependency['model']){ |
| 331 | - $dependency['model'] = $dependency['name']; |
|
| 332 | - } else if(strpos($dependency['model'], '\\') !== false ){ |
|
| 333 | - $dependency['model'] = substr($dependency['model'], strpos($dependency['model'], '\\')+1); |
|
| 334 | - } |
|
| 331 | + $dependency['model'] = $dependency['name']; |
|
| 332 | + } else if(strpos($dependency['model'], '\\') !== false ){ |
|
| 333 | + $dependency['model'] = substr($dependency['model'], strpos($dependency['model'], '\\')+1); |
|
| 334 | + } |
|
| 335 | 335 | $dependency['model'] = studly_case(str_singular($dependency['model'])); |
| 336 | 336 | if ($dependency['model'] != $key) { |
| 337 | 337 | $tmp = $this->getDependencies($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,48 +93,48 @@ discard block |
||
| 93 | 93 | $template = $this->getTemplate($template); |
| 94 | 94 | foreach ($items as $item) { |
| 95 | 95 | $item['type'] = $type; |
| 96 | - if ($parser == 'relations') { |
|
| 97 | - if(! $item['model']){ |
|
| 98 | - $item['model'] = $this->getNamespace() . '\\' . ucwords(str_singular($item['name'])); |
|
| 99 | - } else if(strpos($item['model'], '\\') === false ){ |
|
| 100 | - $item['model'] = $this->getNamespace() . '\\' . $item['model']; |
|
| 101 | - } |
|
| 102 | - } else if ($parser != 'relations') { |
|
| 103 | - switch($type) { |
|
| 104 | - case "hasManyThrough": |
|
| 105 | - if(! $item['through'] && $item['model']){ |
|
| 106 | - $item['through'] = $item['model']; |
|
| 107 | - $item['model'] = $item['name']; |
|
| 108 | - |
|
| 109 | - if(strpos($item['through'], '\\') === false ){ |
|
| 110 | - $item['through'] = $this->getNamespace() . '\\' . ucwords(str_singular($item['through'])); |
|
| 111 | - } |
|
| 112 | - if(strpos($item['model'], '\\') === false ){ |
|
| 113 | - $item['model'] = $this->getNamespace() . '\\' . ucwords(str_singular($item['model'])); |
|
| 114 | - } |
|
| 115 | - } else { |
|
| 116 | - if(strpos($item['through'], '\\') === false ){ |
|
| 117 | - $item['through'] = $this->getNamespace() . '\\' . $item['through']; |
|
| 118 | - } |
|
| 119 | - if(strpos($item['model'], '\\') === false ){ |
|
| 120 | - $item['model'] = $this->getNamespace() . '\\' . $item['model']; |
|
| 121 | - } |
|
| 122 | - } |
|
| 123 | - break; |
|
| 124 | - case "morphMany": |
|
| 125 | - case "morphToMany": |
|
| 126 | - case "morphedByMany": |
|
| 127 | - if(! $item['through']){ |
|
| 128 | - $item['through'] = $item['model']; |
|
| 129 | - $item['model'] = ucwords(str_singular($item['name'])); |
|
| 130 | - } |
|
| 131 | - if(strpos($item['model'], '\\') === false ){ |
|
| 132 | - $item['model'] = $this->getNamespace() . '\\' . $item['model']; |
|
| 133 | - } |
|
| 134 | - break; |
|
| 135 | - |
|
| 136 | - } |
|
| 137 | - } |
|
| 96 | + if ($parser == 'relations') { |
|
| 97 | + if(! $item['model']){ |
|
| 98 | + $item['model'] = $this->getNamespace() . '\\' . ucwords(str_singular($item['name'])); |
|
| 99 | + } else if(strpos($item['model'], '\\') === false ){ |
|
| 100 | + $item['model'] = $this->getNamespace() . '\\' . $item['model']; |
|
| 101 | + } |
|
| 102 | + } else if ($parser != 'relations') { |
|
| 103 | + switch($type) { |
|
| 104 | + case "hasManyThrough": |
|
| 105 | + if(! $item['through'] && $item['model']){ |
|
| 106 | + $item['through'] = $item['model']; |
|
| 107 | + $item['model'] = $item['name']; |
|
| 108 | + |
|
| 109 | + if(strpos($item['through'], '\\') === false ){ |
|
| 110 | + $item['through'] = $this->getNamespace() . '\\' . ucwords(str_singular($item['through'])); |
|
| 111 | + } |
|
| 112 | + if(strpos($item['model'], '\\') === false ){ |
|
| 113 | + $item['model'] = $this->getNamespace() . '\\' . ucwords(str_singular($item['model'])); |
|
| 114 | + } |
|
| 115 | + } else { |
|
| 116 | + if(strpos($item['through'], '\\') === false ){ |
|
| 117 | + $item['through'] = $this->getNamespace() . '\\' . $item['through']; |
|
| 118 | + } |
|
| 119 | + if(strpos($item['model'], '\\') === false ){ |
|
| 120 | + $item['model'] = $this->getNamespace() . '\\' . $item['model']; |
|
| 121 | + } |
|
| 122 | + } |
|
| 123 | + break; |
|
| 124 | + case "morphMany": |
|
| 125 | + case "morphToMany": |
|
| 126 | + case "morphedByMany": |
|
| 127 | + if(! $item['through']){ |
|
| 128 | + $item['through'] = $item['model']; |
|
| 129 | + $item['model'] = ucwords(str_singular($item['name'])); |
|
| 130 | + } |
|
| 131 | + if(strpos($item['model'], '\\') === false ){ |
|
| 132 | + $item['model'] = $this->getNamespace() . '\\' . $item['model']; |
|
| 133 | + } |
|
| 134 | + break; |
|
| 135 | + |
|
| 136 | + } |
|
| 137 | + } |
|
| 138 | 138 | $relations[] = $template->with($item)->get(); |
| 139 | 139 | } |
| 140 | 140 | } |
@@ -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($path = false) |
| 58 | 58 | { |
| 59 | - if (! $path) { |
|
| 60 | - $path = $this->option('path'); |
|
| 61 | - } |
|
| 59 | + if (! $path) { |
|
| 60 | + $path = $this->option('path'); |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - return str_replace(' ', '\\', ucwords(trim(str_replace('/', ' ', $path)))); |
|
| 63 | + return str_replace(' ', '\\', ucwords(trim(str_replace('/', ' ', $path)))); |
|
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | } |
@@ -5,9 +5,9 @@ discard block |
||
| 5 | 5 | |
| 6 | 6 | class ControllerCommand extends BaseCommand { |
| 7 | 7 | |
| 8 | - const DEFAULT_PATH = "app/Http/Controllers"; |
|
| 8 | + const DEFAULT_PATH = "app/Http/Controllers"; |
|
| 9 | 9 | |
| 10 | - protected $signature = 'wn:controller |
|
| 10 | + protected $signature = 'wn:controller |
|
| 11 | 11 | {model : Name of the model (with namespace if not App)} |
| 12 | 12 | {--path='.ControllerCommand::DEFAULT_PATH.' : where to store the controllers file.} |
| 13 | 13 | {--no-routes= : without routes} |
@@ -16,28 +16,28 @@ discard block |
||
| 16 | 16 | {--laravel : Use Laravel style route definitions} |
| 17 | 17 | '; |
| 18 | 18 | |
| 19 | - protected $description = 'Generates RESTful controller using the RESTActions trait'; |
|
| 19 | + protected $description = 'Generates RESTful controller using the RESTActions trait'; |
|
| 20 | 20 | |
| 21 | 21 | public function handle() |
| 22 | 22 | { |
| 23 | - $model = $this->argument('model'); |
|
| 24 | - $name = ''; |
|
| 25 | - if(strrpos($model, "\\") === false){ |
|
| 26 | - $name = $model; |
|
| 27 | - $model = "App\\" . $model; |
|
| 28 | - } else { |
|
| 29 | - $name = explode("\\", $model); |
|
| 30 | - $name = $name[count($name) - 1]; |
|
| 31 | - } |
|
| 23 | + $model = $this->argument('model'); |
|
| 24 | + $name = ''; |
|
| 25 | + if(strrpos($model, "\\") === false){ |
|
| 26 | + $name = $model; |
|
| 27 | + $model = "App\\" . $model; |
|
| 28 | + } else { |
|
| 29 | + $name = explode("\\", $model); |
|
| 30 | + $name = $name[count($name) - 1]; |
|
| 31 | + } |
|
| 32 | 32 | $controller = ucwords(str_plural($name)) . 'Controller'; |
| 33 | 33 | $content = $this->getTemplate('controller') |
| 34 | - ->with([ |
|
| 35 | - 'name' => $controller, |
|
| 36 | - 'model' => $model, |
|
| 37 | - 'namespace' => $this->getNamespace(), |
|
| 38 | - 'use' => ($this->getNamespace() != $this->getDefaultNamespace()?'use '.$this->getDefaultNamespace().'\Controller;'.PHP_EOL.'use '.$this->getDefaultNamespace().'\RESTActions;'.PHP_EOL:'') |
|
| 39 | - ]) |
|
| 40 | - ->get(); |
|
| 34 | + ->with([ |
|
| 35 | + 'name' => $controller, |
|
| 36 | + 'model' => $model, |
|
| 37 | + 'namespace' => $this->getNamespace(), |
|
| 38 | + 'use' => ($this->getNamespace() != $this->getDefaultNamespace()?'use '.$this->getDefaultNamespace().'\Controller;'.PHP_EOL.'use '.$this->getDefaultNamespace().'\RESTActions;'.PHP_EOL:'') |
|
| 39 | + ]) |
|
| 40 | + ->get(); |
|
| 41 | 41 | |
| 42 | 42 | $this->save($content, "./{$this->option('path')}/{$controller}.php", "{$controller}"); |
| 43 | 43 | |
@@ -61,8 +61,8 @@ discard block |
||
| 61 | 61 | } |
| 62 | 62 | } |
| 63 | 63 | |
| 64 | - protected function getDefaultNamespace() { |
|
| 65 | - return $this->getNamespace(ControllerCommand::DEFAULT_PATH); |
|
| 66 | - } |
|
| 64 | + protected function getDefaultNamespace() { |
|
| 65 | + return $this->getNamespace(ControllerCommand::DEFAULT_PATH); |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | 68 | } |
@@ -3,7 +3,7 @@ discard block |
||
| 3 | 3 | |
| 4 | 4 | class MorphTableCommand extends BaseCommand { |
| 5 | 5 | |
| 6 | - protected $signature = 'wn:morph-table |
|
| 6 | + protected $signature = 'wn:morph-table |
|
| 7 | 7 | {model : Name of the persistant model or table} |
| 8 | 8 | {morphable : Name of the morphable identifier} |
| 9 | 9 | {--add= : specifies additional columns like timestamps, softDeletes, rememberToken and nullableTimestamps.} |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | {--force= : override the existing files} |
| 12 | 12 | '; |
| 13 | 13 | |
| 14 | - protected $description = 'Generates creation migration for a morphable pivot table'; |
|
| 14 | + protected $description = 'Generates creation migration for a morphable pivot table'; |
|
| 15 | 15 | |
| 16 | 16 | protected $fields; |
| 17 | 17 | |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | protected function keys() |
| 49 | 49 | { |
| 50 | 50 | // return implode(' ', $this->fields); |
| 51 | - return snake_case(str_singular($this->argument('model')))."_id"; |
|
| 51 | + return snake_case(str_singular($this->argument('model')))."_id"; |
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | } |