Skip to content

Commit

Permalink
Merge branch 'mahmoudmohamedramadan/9.x' into 9.x
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Jun 7, 2022
2 parents bc4e5ea + a62510e commit c8c541c
Show file tree
Hide file tree
Showing 3 changed files with 42 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 @@ -627,4 +627,22 @@ protected function replaceStartsWith($message, $attribute, $rule, $parameters)

return str_replace(':values', implode(', ', $parameters), $message);
}

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

return str_replace(':values', implode(', ', $parameters), $message);
}
}
13 changes: 13 additions & 0 deletions src/Illuminate/Validation/Concerns/ValidatesAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -1949,6 +1949,19 @@ public function validateStartsWith($attribute, $value, $parameters)
{
return Str::startsWith($value, $parameters);
}

/**
* Validate the attribute does not start with a given substring.
*
* @param string $attribute
* @param mixed $value
* @param array<int, int|string> $parameters
* @return bool
*/
public function validateDoesntStartWith($attribute, $value, $parameters)
{
return ! Str::startsWith($value, $parameters);
}

/**
* Validate the attribute ends with a given substring.
Expand Down
11 changes: 11 additions & 0 deletions tests/Validation/ValidationValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2158,6 +2158,17 @@ public function testValidateStartsWith()
$this->assertSame('The url must start with one of the following values http, https', $v->messages()->first('url'));
}

public function testValidateDoesntStartWith()
{
$trans = $this->getIlluminateArrayTranslator();
$v = new Validator($trans, ['x' => 'world hello'], ['x' => 'doesnt_start_with:hello']);
$this->assertTrue($v->passes());

$trans = $this->getIlluminateArrayTranslator();
$v = new Validator($trans, ['x' => 'hello world'], ['x' => 'doesnt_start_with:hello']);
$this->assertFalse($v->passes());
}

public function testValidateString()
{
$trans = $this->getIlluminateArrayTranslator();
Expand Down

0 comments on commit c8c541c

Please sign in to comment.