Skip to content

Commit

Permalink
add multiple_of custom replacer (#34858)
Browse files Browse the repository at this point in the history
  • Loading branch information
timacdonald committed Oct 16, 2020
1 parent 4063a57 commit 11d7470
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/Illuminate/Validation/Concerns/ReplacesAttributes.php
Expand Up @@ -104,6 +104,20 @@ protected function replaceMax($message, $attribute, $rule, $parameters)
return str_replace(':max', $parameters[0], $message);
}

/**
* Replace all place-holders for the multiple_of rule.
*
* @param string $message
* @param string $attribute
* @param string $rule
* @param array $parameters
* @return string
*/
protected function replaceMultipleOf($message, $attribute, $rule, $parameters)
{
return str_replace(':value', $parameters[0], $message);
}

/**
* Replace all place-holders for the in rule.
*
Expand Down
9 changes: 9 additions & 0 deletions tests/Validation/ValidationValidatorTest.php
Expand Up @@ -1857,9 +1857,16 @@ public function testValidateMax()
public function testValidateMutlpleOf($input, $allowed, $passes)
{
$trans = $this->getIlluminateArrayTranslator();
$trans->addLines(['validation.multiple_of' => 'The :attribute must be a multiple of :value'], 'en');

$v = new Validator($trans, ['foo' => $input], ['foo' => "multiple_of:{$allowed}"]);

$this->assertSame($passes, $v->passes());
if ($v->fails()) {
$this->assertSame("The foo must be a multiple of {$allowed}", $v->messages()->first('foo'));
} else {
$this->assertSame('', $v->messages()->first('foo'));
}
}

public function multipleOfDataProvider()
Expand Down Expand Up @@ -1920,6 +1927,8 @@ public function multipleOfDataProvider()
['foo', 1, false], // invalid values
[1, 'foo', false],
['foo', 'foo', false],
[1, '', false],
[1, null, false],
];
}

Expand Down

0 comments on commit 11d7470

Please sign in to comment.