Skip to content

Commit d4ad695

Browse files
committed
Fixes a bug with generating multiple resources
1 parent a0bef72 commit d4ad695

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/Commands/CreateResourcesCommand.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@ class CreateResourcesCommand extends Command
1212
{
1313
use CommonCommand;
1414

15+
/**
16+
* The prefix string to identify a mapping file to create multiple resource
17+
*
18+
* @var string
19+
*/
20+
protected $mapperPrefix = 'mapping-file=';
21+
1522
/**
1623
* The name and signature of the console command.
1724
*
@@ -75,8 +82,8 @@ public function handle()
7582
}
7683

7784

78-
if(starts_with($input->modelName, 'mapping-file=')) {
79-
$filename = str_replace('mapping-file=', '', $input->modelName);
85+
if(starts_with($input->modelName, $this->mapperPrefix)) {
86+
$filename = str_replace($this->mapperPrefix, '', $input->modelName);
8087

8188
$objects = json_decode(Helpers::jsonFileContent($filename));
8289

@@ -94,9 +101,8 @@ public function handle()
94101

95102
$this->validateField($fields);
96103
$validInputs[] = $input;
97-
}
104+
}
98105

99-
100106
foreach($validInputs as $validInput) {
101107
$this->printInfo('Scaffolding resources for ' . $validInput->modelName . '...')
102108
->createModel($validInput)
@@ -333,8 +339,8 @@ protected function createModel($input)
333339
protected function getCommandInput()
334340
{
335341
$modelName = trim($this->argument('model-name'));
336-
//$modelNamePlural = strtolower(str_plural($modelName));
337-
$madeupTableName = $this->makeTableName($modelName);
342+
343+
$madeupTableName = $this->makeTableName(str_replace($this->mapperPrefix, '', $modelName));
338344
$controllerName = trim($this->option('controller-name') ?: ucfirst(Helpers::postFixWith(str_plural($modelName), 'Controller')));
339345
$viewsDirectory = $this->option('views-directory');
340346
$prefix = $this->option('routes-prefix');

0 commit comments

Comments
 (0)