Skip to content

Commit

Permalink
Merge pull request #27341 from sebdesign/5.7
Browse files Browse the repository at this point in the history
[5.7] Show displayable values for relative dates in validation error messages
  • Loading branch information
taylorotwell authored Jan 30, 2019
2 parents 1c74d7f + 3556f5b commit 3fd4405
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
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

0 comments on commit 3fd4405

Please sign in to comment.