From eeebcf9d46b12542845a7a67b275114396d6a557 Mon Sep 17 00:00:00 2001 From: Sean OReilly Date: Tue, 25 Jul 2023 16:04:06 +0100 Subject: [PATCH] Added Ulid validation rule. This commit has * an associated test * all tests passing * updated the docs * ulid validation in laravel is documented here https://laravel.com/docs/9.x/validation#rule-ulid --- docs/advanced-usage/validation-attributes.md | 9 +++++++++ src/Attributes/Validation/Ulid.php | 19 +++++++++++++++++++ .../Validation/ValidationRuleFactory.php | 2 ++ tests/Datasets/Attributes/RulesDataset.php | 6 ++++++ 4 files changed, 36 insertions(+) create mode 100644 src/Attributes/Validation/Ulid.php diff --git a/docs/advanced-usage/validation-attributes.md b/docs/advanced-usage/validation-attributes.md index 0a3bf0db..131b10dc 100644 --- a/docs/advanced-usage/validation-attributes.md +++ b/docs/advanced-usage/validation-attributes.md @@ -888,6 +888,15 @@ public string $closure; public string $closure; ``` +### Ulid + +[Docs](https://laravel.com/docs/9.x/validation#rule-ulid) + +```php +#[Ulid] +public string $closure; +``` + ### Uuid [Docs](https://laravel.com/docs/9.x/validation#rule-uuid) diff --git a/src/Attributes/Validation/Ulid.php b/src/Attributes/Validation/Ulid.php new file mode 100644 index 00000000..9f2db93b --- /dev/null +++ b/src/Attributes/Validation/Ulid.php @@ -0,0 +1,19 @@ + Timezone::class, Unique::keyword() => Unique::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 fbf1d810..ddfd09b4 100644 --- a/tests/Datasets/Attributes/RulesDataset.php +++ b/tests/Datasets/Attributes/RulesDataset.php @@ -83,6 +83,7 @@ use Spatie\LaravelData\Attributes\Validation\Timezone; use Spatie\LaravelData\Attributes\Validation\Unique; use Spatie\LaravelData\Attributes\Validation\Url; +use Spatie\LaravelData\Attributes\Validation\Ulid; use Spatie\LaravelData\Attributes\Validation\Uuid; use Spatie\LaravelData\Exceptions\CannotBuildValidationRule; use Spatie\LaravelData\Support\Validation\ValidationRule; @@ -362,6 +363,11 @@ function fixature( expected: 'url', ); + yield fixature( + attribute: new Ulid(), + expected: 'ulid', + ); + yield fixature( attribute: new Uuid(), expected: 'uuid',