Skip to content

Commit

Permalink
Fix #206
Browse files Browse the repository at this point in the history
  • Loading branch information
sohelamin committed Jan 23, 2018
1 parent f9c9d43 commit cd7af2c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
18 changes: 12 additions & 6 deletions src/Commands/CrudApiCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,23 @@ public function handle()
$foreignKeys = $this->processJSONForeignKeys($this->option('fields_from_file'));
}

$validations = trim($this->option('validations'));
if ($this->option('fields_from_file')) {
$validations = $this->processJSONValidations($this->option('fields_from_file'));
}

$fieldsArray = explode(';', $fields);
$fillableArray = [];

foreach ($fieldsArray as $item) {
$spareParts = explode('#', trim($item));
$fillableArray[] = $spareParts[0];
$modifier = !empty($spareParts[2]) ? $spareParts[2] : 'nullable';

// Process migration fields
$migrationFields .= $spareParts[0] . '#' . $spareParts[1];
$migrationFields .= '#' . $modifier;
$migrationFields .= ';';
}

$commaSeparetedString = implode("', '", $fillableArray);
Expand All @@ -101,16 +112,11 @@ public function handle()
$relationships = $this->processJSONRelationships($this->option('fields_from_file'));
}

$validations = trim($this->option('validations'));
if ($this->option('fields_from_file')) {
$validations = $this->processJSONValidations($this->option('fields_from_file'));
}

$softDeletes = $this->option('soft-deletes');

$this->call('crud:api-controller', ['name' => $controllerNamespace . $name . 'Controller', '--crud-name' => $name, '--model-name' => $modelName, '--model-namespace' => $modelNamespace, '--pagination' => $perPage, '--validations' => $validations]);
$this->call('crud:model', ['name' => $modelNamespace . $modelName, '--fillable' => $fillable, '--table' => $tableName, '--pk' => $primaryKey, '--relationships' => $relationships, '--soft-deletes' => $softDeletes]);
$this->call('crud:migration', ['name' => $migrationName, '--schema' => $fields, '--pk' => $primaryKey, '--indexes' => $indexes, '--foreign-keys' => $foreignKeys, '--soft-deletes' => $softDeletes]);
$this->call('crud:migration', ['name' => $migrationName, '--schema' => $migrationFields, '--pk' => $primaryKey, '--indexes' => $indexes, '--foreign-keys' => $foreignKeys, '--soft-deletes' => $softDeletes]);

// For optimizing the class loader
$this->callSilent('optimize');
Expand Down
5 changes: 2 additions & 3 deletions src/Commands/CrudCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,11 @@ public function handle()
foreach ($fieldsArray as $item) {
$spareParts = explode('#', trim($item));
$fillableArray[] = $spareParts[0];
$modifier = !empty($spareParts[2]) ? $spareParts[2] : 'nullable';

// Process migration fields
$migrationFields .= $spareParts[0] . '#' . $spareParts[1];
if (!preg_match('/' . $spareParts[0] . '/', $validations)) {
$migrationFields .= '#nullable';
}
$migrationFields .= '#' . $modifier;
$migrationFields .= ';';
}

Expand Down
7 changes: 4 additions & 3 deletions src/Commands/CrudModelCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,12 +197,13 @@ protected function replaceSoftDelete(&$stub, $replaceSoftDelete)
*/
protected function createRelationshipFunction(&$stub, $relationshipName, $relationshipType, $argsString)
{
$code = "public function " . $relationshipName . "()\n\t{\n\t\t"
$tabIndent = ' ';
$code = "public function " . $relationshipName . "()\n" . $tabIndent . "{\n" . $tabIndent . $tabIndent
. "return \$this->" . $relationshipType . "(" . $argsString . ");"
. "\n\t}";
. "\n" . $tabIndent . "}";

$str = '{{relationships}}';
$stub = str_replace($str, $code . "\n\t$str", $stub);
$stub = str_replace($str, $code . "\n" . $tabIndent . $str, $stub);

return $this;
}
Expand Down

0 comments on commit cd7af2c

Please sign in to comment.