Skip to content

Commit

Permalink
Merge branch 'fix/starts-with-validation-message' of https://github.c…
Browse files Browse the repository at this point in the history
…om/steffen25/framework into steffen25-fix/starts-with-validation-message
  • Loading branch information
taylorotwell committed Dec 14, 2018
2 parents 69d11ff + 5754ec5 commit 92416bf
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/Illuminate/Validation/Concerns/ReplacesAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -469,4 +469,22 @@ protected function replaceDimensions($message, $attribute, $rule, $parameters)

return $message;
}

/**
* Replace all place-holders for the starts_with rule.
*
* @param string $message
* @param string $attribute
* @param string $rule
* @param array $parameters
* @return string
*/
protected function replaceStartsWith($message, $attribute, $rule, $parameters)
{
foreach ($parameters as &$parameter) {
$parameter = $this->getDisplayableValue($attribute, $parameter);
}

return str_replace(':values', implode(', ', $parameters), $message);
}
}
12 changes: 12 additions & 0 deletions tests/Validation/ValidationValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1211,6 +1211,18 @@ public function testValidateStartsWith()
$trans = $this->getIlluminateArrayTranslator();
$v = new Validator($trans, ['x' => 'hello world'], ['x' => 'starts_with:world,hello']);
$this->assertTrue($v->passes());

$trans = $this->getIlluminateArrayTranslator();
$trans->addLines(['validation.starts_with' => 'The :attribute must start with one of the following values :values'], 'en');
$v = new Validator($trans, ['url' => 'laravel.com'], ['url' => 'starts_with:http']);
$this->assertFalse($v->passes());
$this->assertEquals('The url must start with one of the following values http', $v->messages()->first('url'));

$trans = $this->getIlluminateArrayTranslator();
$trans->addLines(['validation.starts_with' => 'The :attribute must start with one of the following values :values'], 'en');
$v = new Validator($trans, ['url' => 'laravel.com'], ['url' => 'starts_with:http,https']);
$this->assertFalse($v->passes());
$this->assertEquals('The url must start with one of the following values http, https', $v->messages()->first('url'));
}

public function testValidateString()
Expand Down

0 comments on commit 92416bf

Please sign in to comment.