From 84b0ca40bdca31e47d330f63cb30f8a13c4cdfd7 Mon Sep 17 00:00:00 2001 From: Klaas058 Date: Thu, 12 Oct 2023 20:21:39 +0200 Subject: [PATCH] Add Lowercase and Uppercase validation rules --- docs/advanced-usage/validation-attributes.md | 18 ++++++++++++++++++ src/Attributes/Validation/Lowercase.php | 19 +++++++++++++++++++ src/Attributes/Validation/Uppercase.php | 19 +++++++++++++++++++ .../Validation/ValidationRuleFactory.php | 4 ++++ tests/Datasets/Attributes/RulesDataset.php | 12 ++++++++++++ 5 files changed, 72 insertions(+) create mode 100644 src/Attributes/Validation/Lowercase.php create mode 100644 src/Attributes/Validation/Uppercase.php diff --git a/docs/advanced-usage/validation-attributes.md b/docs/advanced-usage/validation-attributes.md index 578db49e..c56362cd 100644 --- a/docs/advanced-usage/validation-attributes.md +++ b/docs/advanced-usage/validation-attributes.md @@ -530,6 +530,15 @@ public int $closure; public int $closure; ``` +### Lowercase + +[Docs](https://laravel.com/docs/9.x/validation#rule-lowercase) + +```php +#[Lowercase] +public string $closure; +``` + ### Max [Docs](https://laravel.com/docs/9.x/validation#rule-max) @@ -888,6 +897,15 @@ public string $closure; public string $closure; ``` +### Uppercase + +[Docs](https://laravel.com/docs/9.x/validation#rule-uppercase) + +```php +#[Uppercase] +public string $closure; +``` + ### Url [Docs](https://laravel.com/docs/9.x/validation#rule-url) diff --git a/src/Attributes/Validation/Lowercase.php b/src/Attributes/Validation/Lowercase.php new file mode 100644 index 00000000..71ead99f --- /dev/null +++ b/src/Attributes/Validation/Lowercase.php @@ -0,0 +1,19 @@ + Json::class, LessThan::keyword() => LessThan::class, LessThanOrEqualTo::keyword() => LessThanOrEqualTo::class, + Lowercase::keyword() => Lowercase::class, Max::keyword() => Max::class, Mimes::keyword() => Mimes::class, MimeTypes::keyword() => MimeTypes::class, @@ -178,6 +181,7 @@ protected function mapping(): array StringType::keyword() => StringType::class, Timezone::keyword() => Timezone::class, Unique::keyword() => Unique::class, + Uppercase::keyword() => Uppercase::class, Url::keyword() => Url::class, Ulid::keyword() => Ulid::class, Uuid::keyword() => Uuid::class, diff --git a/tests/Datasets/Attributes/RulesDataset.php b/tests/Datasets/Attributes/RulesDataset.php index d91fc8f9..8e1e8cbb 100644 --- a/tests/Datasets/Attributes/RulesDataset.php +++ b/tests/Datasets/Attributes/RulesDataset.php @@ -52,6 +52,7 @@ use Spatie\LaravelData\Attributes\Validation\Json; use Spatie\LaravelData\Attributes\Validation\LessThan; use Spatie\LaravelData\Attributes\Validation\LessThanOrEqualTo; +use Spatie\LaravelData\Attributes\Validation\Lowercase; use Spatie\LaravelData\Attributes\Validation\Max; use Spatie\LaravelData\Attributes\Validation\Mimes; use Spatie\LaravelData\Attributes\Validation\MimeTypes; @@ -83,6 +84,7 @@ use Spatie\LaravelData\Attributes\Validation\Timezone; use Spatie\LaravelData\Attributes\Validation\Ulid; use Spatie\LaravelData\Attributes\Validation\Unique; +use Spatie\LaravelData\Attributes\Validation\Uppercase; use Spatie\LaravelData\Attributes\Validation\Url; use Spatie\LaravelData\Attributes\Validation\Uuid; use Spatie\LaravelData\Exceptions\CannotBuildValidationRule; @@ -288,6 +290,11 @@ function fixature( expected: 'lte:field', ); + yield fixature( + attribute: new Lowercase(), + expected: 'lowercase', + ); + yield fixature( attribute: new Max(10), expected: 'max:10', @@ -358,6 +365,11 @@ function fixature( expected: 'timezone', ); + yield fixature( + attribute: new Uppercase(), + expected: 'uppercase', + ); + yield fixature( attribute: new Url(), expected: 'url',