$field) { if(!in_array($fieldName, $excludedNames)) { $validator[$fieldName . ".0"] = 'required|string'; $validator[$fieldName . ".1"] = 'required|string'; if ($generateStructure) { $formStructure['fields'][$fieldName]['title'] = $field[0]; $formStructure['fields'][$fieldName]['type'] = $field[1]; } } } $validatorInstance = Validator::make($fields, $validator); return ($generateStructure) ? collect([ 'validator' => $validatorInstance, 'structure' => json_encode($formStructure) ]) : $validatorInstance; } }