Просмотр исходного кода

validate azienda - visualizzati nome campi "umani"

ferrari 3 месяцев назад
Родитель
Сommit
2b0c08698b
2 измененных файлов с 14 добавлено и 3 удалено
  1. 2 2
      app/Http/Livewire/RecordIN.php
  2. 12 1
      app/Models/Azienda.php

+ 2 - 2
app/Http/Livewire/RecordIN.php

@@ -570,7 +570,7 @@ class RecordIN extends Component
                         if (!$azienda->isValid()) {
                             session()->flash('error_ricevuta', implode("", array_map(function ($item) {
                                 return "<li>$item</li>";
-                            }, array_keys($azienda->validate()))));
+                            }, $azienda->validate())));
                             return false;
                         }
                     }
@@ -876,7 +876,7 @@ class RecordIN extends Component
                         if (!$azienda->isValid()) {
                             session()->flash('error_ricevuta', implode("", array_map(function ($item) {
                                 return "<li>$item</li>";
-                            }, array_keys($azienda->validate()))));
+                            }, $azienda->validate())));
                             return false;
                         }
                     }

+ 12 - 1
app/Models/Azienda.php

@@ -60,10 +60,21 @@ class Azienda extends Model
             'cellulare' => 'required|string|max:20',
         ];
 
+        $rules_human = [
+            'ragione_sociale' => "Ragione sociale",
+            'email' => "Email",
+            'pec' => "Pec",
+            'cellulare' => "Cellulare",
+        ];
+
         $validator = Validator::make($this->attributesToArray(), $rules);
 
         if ($validator->fails()) {
-            return $validator->errors()->toArray();
+            $errors = [];
+            foreach ($validator->errors()->messages() as $field => $error) {
+                $errors[$field] = isset($rules_human[$field]) ? $rules_human[$field] : $field;
+            }
+            return $errors;
         }
 
         return true;