From 8a7fe27159fa4c8a742e0171be25d76a9b9e40c2 Mon Sep 17 00:00:00 2001 From: mike Date: Mon, 13 Jun 2022 23:46:23 +0300 Subject: [PATCH] There can be several rules with the same name for a field --- src/Attribute.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Attribute.php b/src/Attribute.php index ebd7a11..c3626a1 100644 --- a/src/Attribute.php +++ b/src/Attribute.php @@ -47,8 +47,10 @@ public function __construct( $this->validation = $validation; $this->alias = $alias; $this->key = $key; + $rule_number = 0; foreach ($rules as $rule) { - $this->addRule($rule); + $this->addRule($rule, $rule_number); + $rule_number++; } } @@ -125,11 +127,11 @@ public function getOtherAttributes(): array * @param \Rakit\Validation\Rule $rule * @return void */ - public function addRule(Rule $rule) + public function addRule(Rule $rule, int $rule_number) { $rule->setAttribute($this); $rule->setValidation($this->validation); - $this->rules[$rule->getKey()] = $rule; + $this->rules[$rule->getKey() . (string)$rule_number] = $rule; } /**