Skip to content

Commit

Permalink
Merge branch '8.x' into 9.x
Browse files Browse the repository at this point in the history
  • Loading branch information
GrahamCampbell committed May 27, 2022
2 parents 6999399 + c6d1a2d commit e4e40df
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/Illuminate/Validation/Concerns/FormatsMessages.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -50,7 +54,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
Expand Down
4 changes: 3 additions & 1 deletion src/Illuminate/Validation/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,8 @@ public function addFailure($attribute, $rule, $parameters = [])
$this->passes();
}

$attributeWithPlaceholders = $attribute;

$attribute = str_replace(
[$this->dotPlaceholder, '__asterisk__'],
['.', '*'],
Expand All @@ -876,7 +878,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;
Expand Down
22 changes: 22 additions & 0 deletions tests/Validation/ValidationValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7193,6 +7193,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);
Expand Down

0 comments on commit e4e40df

Please sign in to comment.