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

[5.7] Show displayable values for relative dates in validation error messages #27341

Merged
merged 1 commit into from
Jan 30, 2019
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Illuminate/Validation/Concerns/ReplacesAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -385,11 +385,11 @@ protected function replaceSame($message, $attribute, $rule, $parameters)
*/
protected function replaceBefore($message, $attribute, $rule, $parameters)
{
if (! (strtotime($parameters[0]))) {
if (! strtotime($parameters[0])) {
return str_replace(':date', $this->getDisplayableAttribute($parameters[0]), $message);
}

return str_replace(':date', $parameters[0], $message);
return str_replace(':date', $this->getDisplayableValue($attribute, $parameters[0]), $message);
}

/**
Expand Down
9 changes: 9 additions & 0 deletions tests/Validation/ValidationValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,15 @@ public function testDisplayableValuesAreReplaced()
$v->messages()->setFormat(':message');
$this->assertEquals('type must be included in Short, Long.', $v->messages()->first('type'));

//date_equals:tomorrow
$trans = $this->getIlluminateArrayTranslator();
$trans->addLines(['validation.date_equals' => 'The :attribute must be a date equal to :date.'], 'en');
$trans->addLines(['validation.values.date.tomorrow' => 'the day after today'], 'en');
$v = new Validator($trans, ['date' => date('Y-m-d')], ['date' => 'date_equals:tomorrow']);
$this->assertFalse($v->passes());
$v->messages()->setFormat(':message');
$this->assertEquals('The date must be a date equal to the day after today.', $v->messages()->first('date'));

// test addCustomValues
$trans = $this->getIlluminateArrayTranslator();
$trans->addLines(['validation.in' => ':attribute must be included in :values.'], 'en');
Expand Down