Skip to content

Commit

Permalink
JSON Field supported
Browse files Browse the repository at this point in the history
  • Loading branch information
sohelamin committed Dec 9, 2016
1 parent 6ba49e8 commit ed539c1
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/Commands/CrudCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class CrudCommand extends Command
protected $signature = 'crud:generate
{name : The name of the Crud.}
{--fields= : Fields name for the form & migration.}
{--fields_from_file= : Fields from a json file.}
{--validations= : Validation details for the fields.}
{--controller-namespace= : Namespace of the controller.}
{--model-namespace= : Namespace of the model inside "app" dir.}
Expand Down Expand Up @@ -73,6 +74,10 @@ public function handle()

$fields = rtrim($this->option('fields'), ';');

if ($this->option('fields_from_file')) {
$fields = $this->processJSONFields($this->option('fields_from_file'));
}

$primaryKey = $this->option('pk');
$viewPath = $this->option('view-path');

Expand Down Expand Up @@ -136,4 +141,30 @@ protected function addRoutes()
{
return ["Route::resource('" . $this->routeName . "', '" . $this->controller . "');"];
}

/**
* Process the JSON Fields.
*
* @param string $file
*
* @return string
*/
protected function processJSONFields($file)
{
$json = File::get($file);
$fields = json_decode($json);

$fieldsString = '';
foreach ($fields->fields as $field) {
if ($field->type == 'select') {
$fieldsString .= $field->name . '#' . $field->type . '#options=' . implode(',', $field->options) . ';';
} else {
$fieldsString .= $field->name . '#' . $field->type . ';';
}
}

$fieldsString = rtrim($fieldsString, ';');

return $fieldsString;
}
}

0 comments on commit ed539c1

Please sign in to comment.