public function handle() { $this->commandData->modelName = $this->argument('model'); $this->commandData->useSoftDelete = $this->option('softDelete'); $this->commandData->useSearch = $this->option('search'); $this->commandData->fieldsFile = $this->option('fieldsFile'); $this->commandData->initVariables(); if ($this->commandData->fieldsFile) { $fileHelper = new FileHelper(); try { if (file_exists($this->commandData->fieldsFile)) { $filePath = $this->commandData->fieldsFile; } else { $filePath = base_path($this->commandData->fieldsFile); } if (!file_exists($filePath)) { $this->commandData->commandObj->error("Fields file not found"); exit; } $fileContents = $fileHelper->getFileContents($filePath); $fields = json_decode($fileContents, true); $this->commandData->inputFields = GeneratorUtils::validateFieldsFile($fields); } catch (Exception $e) { $this->commandData->commandObj->error($e->getMessage()); exit; } } else { $this->commandData->inputFields = $this->commandData->getInputFields(); } }
public function getInputFields() { $fields = []; $this->commandObj->info("Specify fields for the model (skip id & timestamp fields, will be added automatically)"); $this->commandObj->info("Left blank to finish"); while (true) { $fieldInputStr = $this->commandObj->ask("Field:"); if (empty($fieldInputStr)) { break; } if (!GeneratorUtils::validateFieldInput($fieldInputStr)) { $this->commandObj->error("Invalid Input. Try again"); continue; } $validations = $this->commandObj->ask("Enter validations: "); $fields[] = GeneratorUtils::processFieldInput($fieldInputStr, $validations); } return $fields; }