diff --git a/src/Illuminate/Validation/Concerns/FormatsMessages.php b/src/Illuminate/Validation/Concerns/FormatsMessages.php index c95cd3a8051..c7c9a1dcb8c 100644 --- a/src/Illuminate/Validation/Concerns/FormatsMessages.php +++ b/src/Illuminate/Validation/Concerns/FormatsMessages.php @@ -20,6 +20,10 @@ trait FormatsMessages */ protected function getMessage($attribute, $rule) { + $attributeWithPlaceholders = $attribute; + + $attribute = $this->replacePlaceholderInString($attribute); + $inlineMessage = $this->getInlineMessage($attribute, $rule); // First we will retrieve the custom message for the validation rule if one @@ -46,7 +50,7 @@ protected function getMessage($attribute, $rule) // specific error message for the type of attribute being validated such // as a number, file or string which all have different message types. elseif (in_array($rule, $this->sizeRules)) { - return $this->getSizeMessage($attribute, $rule); + return $this->getSizeMessage($attributeWithPlaceholders, $rule); } // Finally, if no developer specified messages have been set, and no other diff --git a/src/Illuminate/Validation/Validator.php b/src/Illuminate/Validation/Validator.php index f79314da47a..9cbc91b2ff3 100755 --- a/src/Illuminate/Validation/Validator.php +++ b/src/Illuminate/Validation/Validator.php @@ -867,6 +867,8 @@ public function addFailure($attribute, $rule, $parameters = []) $this->passes(); } + $attributeWithPlaceholders = $attribute; + $attribute = str_replace( [$this->dotPlaceholder, '__asterisk__'], ['.', '*'], @@ -878,7 +880,7 @@ public function addFailure($attribute, $rule, $parameters = []) } $this->messages->add($attribute, $this->makeReplacements( - $this->getMessage($attribute, $rule), $attribute, $rule, $parameters + $this->getMessage($attributeWithPlaceholders, $rule), $attribute, $rule, $parameters )); $this->failedRules[$attribute][$rule] = $parameters; diff --git a/tests/Validation/ValidationValidatorTest.php b/tests/Validation/ValidationValidatorTest.php index add01e7d82a..bde76a9672c 100755 --- a/tests/Validation/ValidationValidatorTest.php +++ b/tests/Validation/ValidationValidatorTest.php @@ -7158,6 +7158,28 @@ public function testArrayKeysValidationFailsWithNotAnArray() ); } + public function testArrayKeysWithDotIntegerMin() + { + $trans = $this->getIlluminateArrayTranslator(); + + $data = [ + 'foo.bar' => -1, + ]; + + $rules = [ + 'foo\.bar' => 'integer|min:1', + ]; + + $expectedResult = [ + 'foo.bar' => [ + 'validation.min.numeric', + ], + ]; + + $validator = new Validator($trans, $data, $rules, [], []); + $this->assertEquals($expectedResult, $validator->getMessageBag()->getMessages()); + } + protected function getTranslator() { return m::mock(TranslatorContract::class);