From 2be6e6d63cdf2d4d39dfb0a29e4cc894159623b3 Mon Sep 17 00:00:00 2001 From: Muhammad Rizwan Date: Thu, 4 Jul 2024 10:55:15 +0300 Subject: [PATCH] Fix: customer messages --- src/ValidationMyPhp/Validation.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/ValidationMyPhp/Validation.php b/src/ValidationMyPhp/Validation.php index 68bbd35..8eed727 100644 --- a/src/ValidationMyPhp/Validation.php +++ b/src/ValidationMyPhp/Validation.php @@ -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 );