From 4f9f035c699e1528af1ad4931475e2c6036b39ab Mon Sep 17 00:00:00 2001 From: spencerrlongg Date: Mon, 30 Sep 2024 20:09:00 -0500 Subject: [PATCH] added a way to manipulate validator attribute names --- app/Http/Controllers/AssetModelsController.php | 7 ++++++- .../custom-field-set-default-values-for-model.blade.php | 1 - 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/AssetModelsController.php b/app/Http/Controllers/AssetModelsController.php index 51b0fceca8..aa083e1ae3 100755 --- a/app/Http/Controllers/AssetModelsController.php +++ b/app/Http/Controllers/AssetModelsController.php @@ -483,7 +483,12 @@ class AssetModelsController extends Controller $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(); diff --git a/resources/views/livewire/custom-field-set-default-values-for-model.blade.php b/resources/views/livewire/custom-field-set-default-values-for-model.blade.php index 8f0be5f0c9..9f09d111b1 100644 --- a/resources/views/livewire/custom-field-set-default-values-for-model.blade.php +++ b/resources/views/livewire/custom-field-set-default-values-for-model.blade.php @@ -127,7 +127,6 @@ first($field->db_column_name()); if ($errormessage) { - $errormessage = preg_replace('/snipeit|\d+/', '', $errormessage); print(''); } ?>