Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/Illuminate/Validation/Concerns/ValidatesAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -1196,6 +1196,19 @@ public function validateUppercase($attribute, $value, $parameters)
return Str::upper($value) === $value;
}

/**
* Validate that an attribute is snakecase.
*
* @param string $attribute
* @param mixed $value
* @param array<int, int|string> $parameters
* @return bool
*/
public function validateSnakecase($attribute, $value, $parameters)
{
return Str::snake($value) === $value;
}

/**
* Validate the MIME type of a file is an image MIME type.
*
Expand Down
36 changes: 36 additions & 0 deletions tests/Validation/ValidationValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1857,6 +1857,42 @@ public function testUppercase()
], $v->messages()->keys());
}

public function testSnakecase()
{
$trans = $this->getIlluminateArrayTranslator();
$v = new Validator($trans, [
'lower' => 'lowercase',
'mixed' => 'MixedCase',
'upper' => 'UPPERCASE',
'lower_multibyte' => 'carácter_multibyte',
'mixed_multibyte' => 'carÁcter_multibyte',
'upper_multibyte' => 'CARÁCTER_MULTIBYTE',
'lower_multibyte_space' => 'carácter multibyte',
'mixed_multibyte_space' => 'carÁcter multibyte',
'upper_multibyte_space' => 'CARÁCTER MULTIBYTE',
], [
'lower' => 'snakecase',
'mixed' => 'snakecase',
'upper' => 'snakecase',
'lower_multibyte' => 'snakecase',
'mixed_multibyte' => 'snakecase',
'upper_multibyte' => 'snakecase',
'lower_multibyte_space' => 'snakecase',
'mixed_multibyte_space' => 'snakecase',
'upper_multibyte_space' => 'snakecase',
]);

$this->assertSame([
'mixed',
'upper',
'mixed_multibyte',
'upper_multibyte',
'lower_multibyte_space',
'mixed_multibyte_space',
'upper_multibyte_space',
], $v->messages()->keys());
}

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