Skip to content

Commit

Permalink
Fix: customer messages
Browse files Browse the repository at this point in the history
  • Loading branch information
rizwan3d committed Jul 4, 2024
1 parent 07f3d40 commit 2be6e6d
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/ValidationMyPhp/Validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,19 @@ public function validate(array $data, array $fields, array $messages = []): arra
$rule = new $fn();
$pass = $rule->check($data, $field, ...$params);
if (!$pass) {

$msg = $rule->message;
if(is_array($messages[$field])){
$msg = $messages[$field][$rule_name] ?? $rule->message;
}
else{
$msg = $messages[$field] ?? $rule->message;
}

// get the error message for a specific field and rule if exists
// otherwise get the error message from the $validation_errors
$errors[$field][] = sprintf(
$messages[$field][$rule_name] ?? $rule->message,
$msg,
$field,
...$params
);
Expand Down

0 comments on commit 2be6e6d

Please sign in to comment.