diff --git a/src/Illuminate/Validation/Concerns/FormatsMessages.php b/src/Illuminate/Validation/Concerns/FormatsMessages.php index f433a5361eec..a5983d111d24 100644 --- a/src/Illuminate/Validation/Concerns/FormatsMessages.php +++ b/src/Illuminate/Validation/Concerns/FormatsMessages.php @@ -31,9 +31,11 @@ protected function getMessage($attribute, $rule) $lowerRule = Str::snake($rule); - $customMessage = $this->getCustomMessageFromTranslator( - $customKey = "validation.custom.{$attribute}.{$lowerRule}" - ); + $customKey = in_array($rule, $this->sizeRules) + ? "validation.custom.{$attribute}.{$lowerRule}.{$this->getAttributeType($attribute)}" + : "validation.custom.{$attribute}.{$lowerRule}"; + + $customMessage = $this->getCustomMessageFromTranslator($customKey); // First we check for a custom defined validation message for the attribute // and rule. This allows the developer to specify specific messages for diff --git a/tests/Validation/ValidationValidatorTest.php b/tests/Validation/ValidationValidatorTest.php index d1d3d424dd59..fef4ee42069c 100755 --- a/tests/Validation/ValidationValidatorTest.php +++ b/tests/Validation/ValidationValidatorTest.php @@ -598,6 +598,28 @@ public function testCustomValidationLinesAreRespected() $this->assertSame('really required!', $v->messages()->first('name')); } + public function testCustomValidationLinesForSizeRules() + { + $trans = $this->getIlluminateArrayTranslator(); + $trans->getLoader()->addMessages('en', 'validation', [ + 'required' => 'required!', + 'custom' => [ + 'name' => [ + 'between' => [ + 'numeric' => 'The :attribute must be between :min and :max.', + 'file' => 'The :attribute must be between :min and :max kilobytes.', + 'string' => 'Some custom message here', + 'array' => 'The :attribute must have between :min and :max items.', + ], + ], + ], + ]); + $v = new Validator($trans, ['name' => 'Taylor'], ['name' => 'between:10,20']); + $this->assertFalse($v->passes()); + $v->messages()->setFormat(':message'); + $this->assertSame('Some custom message here', $v->messages()->first('name')); + } + public function testCustomValidationLinesAreRespectedWithAsterisks() { $trans = $this->getIlluminateArrayTranslator();