diff --git a/src/Illuminate/Validation/Concerns/ReplacesAttributes.php b/src/Illuminate/Validation/Concerns/ReplacesAttributes.php index 04009d171e6a..901ce6b255a6 100644 --- a/src/Illuminate/Validation/Concerns/ReplacesAttributes.php +++ b/src/Illuminate/Validation/Concerns/ReplacesAttributes.php @@ -610,6 +610,24 @@ protected function replaceEndsWith($message, $attribute, $rule, $parameters) return str_replace(':values', implode(', ', $parameters), $message); } + /** + * Replace all place-holders for the doesnt_end_with rule. + * + * @param string $message + * @param string $attribute + * @param string $rule + * @param array $parameters + * @return string + */ + protected function replaceDoesntEndWith($message, $attribute, $rule, $parameters) + { + foreach ($parameters as &$parameter) { + $parameter = $this->getDisplayableValue($attribute, $parameter); + } + + return str_replace(':values', implode(', ', $parameters), $message); + } + /** * Replace all place-holders for the starts_with rule. * diff --git a/src/Illuminate/Validation/Concerns/ValidatesAttributes.php b/src/Illuminate/Validation/Concerns/ValidatesAttributes.php index c76254ac0883..b6f64dd0679f 100644 --- a/src/Illuminate/Validation/Concerns/ValidatesAttributes.php +++ b/src/Illuminate/Validation/Concerns/ValidatesAttributes.php @@ -1976,6 +1976,19 @@ public function validateEndsWith($attribute, $value, $parameters) return Str::endsWith($value, $parameters); } + /** + * Validate the attribute does not end with a given substring. + * + * @param string $attribute + * @param mixed $value + * @param array $parameters + * @return bool + */ + public function validateDoesntEndWith($attribute, $value, $parameters) + { + return ! Str::endsWith($value, $parameters); + } + /** * Validate that an attribute is a string. * diff --git a/tests/Validation/ValidationValidatorTest.php b/tests/Validation/ValidationValidatorTest.php index 5ad2eee28961..28ff228173ab 100755 --- a/tests/Validation/ValidationValidatorTest.php +++ b/tests/Validation/ValidationValidatorTest.php @@ -2131,6 +2131,17 @@ public function testValidateEndsWith() $this->assertSame('The url must end with one of the following values http, https', $v->messages()->first('url')); } + public function testValidateDoesntEndWith() + { + $trans = $this->getIlluminateArrayTranslator(); + $v = new Validator($trans, ['x' => 'hello world'], ['x' => 'doesnt_end_with:hello']); + $this->assertTrue($v->passes()); + + $trans = $this->getIlluminateArrayTranslator(); + $v = new Validator($trans, ['x' => 'hello world'], ['x' => 'doesnt_end_with:world']); + $this->assertFalse($v->passes()); + } + public function testValidateStartsWith() { $trans = $this->getIlluminateArrayTranslator();