InfyOm\Generator\Utils\GeneratorFieldsInputUtil::validateFieldInput PHP Method

validateFieldInput() public static method

public static validateFieldInput ( $fieldInputStr )
    public static function validateFieldInput($fieldInputStr)
    {
        $fieldInputs = explode(':', $fieldInputStr);
        if (count($fieldInputs) < 2) {
            return false;
        }
        return true;
    }

Usage Example

 private function getInputFromConsole()
 {
     $this->commandInfo('Specify fields for the model (skip id & timestamp fields, we will add it automatically)');
     $this->commandInfo('Enter "exit" to finish');
     $this->addPrimaryKey();
     while (true) {
         $fieldInputStr = $this->commandObj->ask('Field: (field_name:field_database_type)', '');
         if (empty($fieldInputStr) || $fieldInputStr == false || $fieldInputStr == 'exit') {
             break;
         }
         if (!GeneratorFieldsInputUtil::validateFieldInput($fieldInputStr)) {
             $this->commandError('Invalid Input. Try again');
             continue;
         }
         if ($this->commandType == self::$COMMAND_TYPE_SCAFFOLD or $this->commandType == self::$COMMAND_TYPE_API_SCAFFOLD) {
             $htmlType = $this->commandObj->ask('Enter field html input type (text): ', 'text');
         } else {
             $htmlType = '';
         }
         $validations = $this->commandObj->ask('Enter validations: ', false);
         $searchable = $this->commandObj->ask('Is Searchable (y/N): ', false);
         $validations = $validations == false ? '' : $validations;
         if ($searchable) {
             $searchable = strtolower($searchable) == 'y' ? true : false;
         }
         $this->inputFields[] = GeneratorFieldsInputUtil::processFieldInput($fieldInputStr, $htmlType, $validations, ['searchable' => $searchable]);
     }
     $this->addTimestamps();
 }