public static function validateFieldsFile($fields)
{
$fieldsArr = [];
foreach ($fields as $field) {
if (!self::validateFieldInput($field['fieldInput'])) {
throw new RuntimeException('Invalid Input ' . $field['fieldInput']);
}
if (isset($field['htmlType'])) {
$htmlType = $field['htmlType'];
} else {
$htmlType = 'text';
}
if (isset($field['validations'])) {
$validations = $field['validations'];
} else {
$validations = '';
}
if (isset($field['searchable'])) {
$searchable = $field['searchable'];
} else {
$searchable = false;
}
if (isset($field['fillable'])) {
$fillable = $field['fillable'];
} else {
$fillable = true;
}
if (isset($field['primary'])) {
$primary = $field['primary'];
} else {
$primary = false;
}
if (isset($field['inForm'])) {
$inForm = $field['inForm'];
} elseif ($primary) {
$inForm = false;
} else {
$inForm = true;
}
if (isset($field['inIndex'])) {
$inIndex = $field['inIndex'];
} elseif ($primary) {
$inIndex = false;
} else {
$inIndex = true;
}
$fieldSettings = ['searchable' => $searchable, 'fillable' => $fillable, 'primary' => $primary, 'inForm' => $inForm, 'inIndex' => $inIndex];
$fieldsArr[] = self::processFieldInput($field['fieldInput'], $htmlType, $validations, $fieldSettings);
}
return $fieldsArr;
}
private function getInputFromFileOrJson() { // fieldsFile option will get high priority than json option if both options are passed try { if ($this->getOption('fieldsFile')) { if (file_exists($this->getOption('fieldsFile'))) { $filePath = $this->getOption('fieldsFile'); } else { $filePath = base_path($this->getOption('fieldsFile')); } if (!file_exists($filePath)) { $this->commandError('Fields file not found'); exit; } $fileContents = file_get_contents($filePath); $jsonData = json_decode($fileContents, true); $this->inputFields = array_merge($this->inputFields, GeneratorFieldsInputUtil::validateFieldsFile($jsonData)); } else { $fileContents = $this->getOption('jsonFromGUI'); $jsonData = json_decode($fileContents, true); $this->inputFields = array_merge($this->inputFields, GeneratorFieldsInputUtil::validateFieldsFile($jsonData['fields'])); $this->config->overrideOptionsFromJsonFile($jsonData); if (isset($jsonData['migrate'])) { $this->config->forceMigrate = $jsonData['migrate']; } } $this->checkForDiffPrimaryKey(); } catch (Exception $e) { $this->commandError($e->getMessage()); exit; } }