Skip to content

Commit 2be6e6d

Browse files
committed
Fix: customer messages
1 parent 07f3d40 commit 2be6e6d

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/ValidationMyPhp/Validation.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,19 @@ public function validate(array $data, array $fields, array $messages = []): arra
5050
$rule = new $fn();
5151
$pass = $rule->check($data, $field, ...$params);
5252
if (!$pass) {
53+
54+
$msg = $rule->message;
55+
if(is_array($messages[$field])){
56+
$msg = $messages[$field][$rule_name] ?? $rule->message;
57+
}
58+
else{
59+
$msg = $messages[$field] ?? $rule->message;
60+
}
61+
5362
// get the error message for a specific field and rule if exists
5463
// otherwise get the error message from the $validation_errors
5564
$errors[$field][] = sprintf(
56-
$messages[$field][$rule_name] ?? $rule->message,
65+
$msg,
5766
$field,
5867
...$params
5968
);

0 commit comments

Comments
 (0)