Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/Illuminate/Validation/Concerns/FormatsMessages.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 22 additions & 0 deletions tests/Validation/ValidationValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down