diff --git a/src/Illuminate/Validation/Validator.php b/src/Illuminate/Validation/Validator.php index 821503762aa4..a92bc043df91 100755 --- a/src/Illuminate/Validation/Validator.php +++ b/src/Illuminate/Validation/Validator.php @@ -2123,7 +2123,7 @@ protected function getCustomMessageFromTranslator($customKey) ); foreach ($customMessages as $key => $message) { - if (Str::contains($key, ['*']) && Str::is($key, $shortKey)) { + if ($shortKey === $key || (Str::contains($key, ['*']) && Str::is($key, $shortKey))) { return $message; } } diff --git a/tests/Validation/ValidationValidatorTest.php b/tests/Validation/ValidationValidatorTest.php index a8c6a540ab14..885e7ab1ed9a 100755 --- a/tests/Validation/ValidationValidatorTest.php +++ b/tests/Validation/ValidationValidatorTest.php @@ -391,14 +391,19 @@ public function testCustomValidationLinesAreRespectedWithAsterisks() 'name.*' => [ 'required' => 'all are really required!', ], + 'lang.en' => [ + 'required' => 'english is required!', + ], ], ]); - $v = new Validator($trans, ['name' => ['', '']], []); + $v = new Validator($trans, ['name' => ['', ''], 'lang' => ['en' => '']], []); $v->each('name', 'required|max:255'); + $v->each('lang.*', 'required|max:255'); $this->assertFalse($v->passes()); $v->messages()->setFormat(':message'); $this->assertEquals('all are really required!', $v->messages()->first('name.0')); $this->assertEquals('all are really required!', $v->messages()->first('name.1')); + $this->assertEquals('english is required!', $v->messages()->first('lang.en')); } public function testValidationDotCustomDotAnythingCanBeTranslated()