Skip to content

Commit c8c541c

Browse files
committed
Merge branch 'mahmoudmohamedramadan/9.x' into 9.x
2 parents bc4e5ea + a62510e commit c8c541c

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

src/Illuminate/Validation/Concerns/ReplacesAttributes.php

+18
Original file line numberDiff line numberDiff line change
@@ -627,4 +627,22 @@ protected function replaceStartsWith($message, $attribute, $rule, $parameters)
627627

628628
return str_replace(':values', implode(', ', $parameters), $message);
629629
}
630+
631+
/**
632+
* Replace all place-holders for the doesnt_start_with rule.
633+
*
634+
* @param string $message
635+
* @param string $attribute
636+
* @param string $rule
637+
* @param array<int,string> $parameters
638+
* @return string
639+
*/
640+
protected function replaceDoesntStartWith($message, $attribute, $rule, $parameters)
641+
{
642+
foreach ($parameters as &$parameter) {
643+
$parameter = $this->getDisplayableValue($attribute, $parameter);
644+
}
645+
646+
return str_replace(':values', implode(', ', $parameters), $message);
647+
}
630648
}

src/Illuminate/Validation/Concerns/ValidatesAttributes.php

+13
Original file line numberDiff line numberDiff line change
@@ -1949,6 +1949,19 @@ public function validateStartsWith($attribute, $value, $parameters)
19491949
{
19501950
return Str::startsWith($value, $parameters);
19511951
}
1952+
1953+
/**
1954+
* Validate the attribute does not start with a given substring.
1955+
*
1956+
* @param string $attribute
1957+
* @param mixed $value
1958+
* @param array<int, int|string> $parameters
1959+
* @return bool
1960+
*/
1961+
public function validateDoesntStartWith($attribute, $value, $parameters)
1962+
{
1963+
return ! Str::startsWith($value, $parameters);
1964+
}
19521965

19531966
/**
19541967
* Validate the attribute ends with a given substring.

tests/Validation/ValidationValidatorTest.php

+11
Original file line numberDiff line numberDiff line change
@@ -2158,6 +2158,17 @@ public function testValidateStartsWith()
21582158
$this->assertSame('The url must start with one of the following values http, https', $v->messages()->first('url'));
21592159
}
21602160

2161+
public function testValidateDoesntStartWith()
2162+
{
2163+
$trans = $this->getIlluminateArrayTranslator();
2164+
$v = new Validator($trans, ['x' => 'world hello'], ['x' => 'doesnt_start_with:hello']);
2165+
$this->assertTrue($v->passes());
2166+
2167+
$trans = $this->getIlluminateArrayTranslator();
2168+
$v = new Validator($trans, ['x' => 'hello world'], ['x' => 'doesnt_start_with:hello']);
2169+
$this->assertFalse($v->passes());
2170+
}
2171+
21612172
public function testValidateString()
21622173
{
21632174
$trans = $this->getIlluminateArrayTranslator();

0 commit comments

Comments
 (0)