Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8.x] Add multiple_of custom replacer #34858

Merged
merged 1 commit into from Oct 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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