Skip to content

Commit

Permalink
added a way to manipulate validator attribute names
Browse files Browse the repository at this point in the history
  • Loading branch information
spencerrlongg committed Oct 1, 2024
1 parent cd3059f commit 4f9f035
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
7 changes: 6 additions & 1 deletion app/Http/Controllers/AssetModelsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,12 @@ private function assignCustomFieldsDefaultValues(AssetModel|SnipeModel $model, a
$rules[$field] = $validation;
}

$validator = Validator::make($data, $rules);
$attributes = [];
foreach ($model->fieldset->fields as $field) {
$attributes[$field->db_column] = trim(preg_replace('/_+|snipeit|\d+/', ' ', $field->db_column));
}

$validator = Validator::make($data, $rules)->setAttributeNames($attributes);

if($validator->fails()){
$this->validatorErrors = $validator->errors();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ class="form-control"
<?php
$errormessage = $errors->first($field->db_column_name());
if ($errormessage) {
$errormessage = preg_replace('/snipeit|\d+/', '', $errormessage);
print('<span class="alert-msg" aria-hidden="true"><i class="fas fa-times" aria-hidden="true"></i> '.$errormessage.'</span>');
}
?>
Expand Down

0 comments on commit 4f9f035

Please sign in to comment.