Skip to content

Commit

Permalink
[7.x] Fix: replaceInputPlaceholder() should replace :input by its dis…
Browse files Browse the repository at this point in the history
…playable value (laravel#30878)

* Fix: replaceInputPlaceholder() should replace :input by its displayable value

* Test: testInputIsReplacedByItsDisplayableValue()
  • Loading branch information
mpyw authored and taylorotwell committed Dec 19, 2019
1 parent 24e7037 commit 3b7b291
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Illuminate/Validation/Concerns/FormatsMessages.php
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ protected function replaceInputPlaceholder($message, $attribute)
$actualValue = $this->getValue($attribute);

if (is_scalar($actualValue) || is_null($actualValue)) {
$message = str_replace(':input', $actualValue, $message);
$message = str_replace(':input', $this->getDisplayableValue($attribute, $actualValue), $message);
}

return $message;
Expand Down
21 changes: 21 additions & 0 deletions tests/Validation/ValidationValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,27 @@ public function testInputIsReplaced()
$this->assertSame(' is not a valid email', $v->messages()->first('email'));
}

public function testInputIsReplacedByItsDisplayableValue()
{
$frameworks = [
1 => 'Laravel',
2 => 'Symfony',
3 => 'Rails',
];

$trans = $this->getIlluminateArrayTranslator();
$trans->addLines(['validation.framework_php' => ':input is not a valid PHP Framework'], 'en');

$v = new Validator($trans, ['framework' => 3], ['framework' => 'framework_php']);
$v->addExtension('framework_php', function ($attribute, $value, $parameters, $validator) {
return in_array($value, [1, 2]);
});
$v->addCustomValues(['framework' => $frameworks]);

$this->assertFalse($v->passes());
$this->assertSame('Rails is not a valid PHP Framework', $v->messages()->first('framework'));
}

public function testDisplayableValuesAreReplaced()
{
//required_if:foo,bar
Expand Down

0 comments on commit 3b7b291

Please sign in to comment.