diff --git a/CHANGELOG.md b/CHANGELOG.md index a7ea194..13dd7c0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,15 @@ # Changelog -All notable changes to `laravel-mixins` will be documented in this file +All notable changes to `laravel-mixins` will be documented in this file. -## 1.0.0 - 2020-08-xx +## 2.1.0 - 2020-10-13 -- Initial release +- Added `InKeys` rule. + +## 2.0.0 - 2020-10-05 + +- [ConvertsBase64ToFiles] Renamed `base64ImageKeys` to `base64FileKeys`. + +## 1.0.0 - 2020-09-22 + +- Initial release. diff --git a/README.md b/README.md index e67cae3..4c6a504 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,7 @@ There's no Service Provider or automatic discovery/registration of anything. All * [Current password](#current-password) * [Dimensions With Margin](#dimensions-with-margin) * [Host](#host) +* [In Keys](#in-keys) * [Max Words](#max-words) * [URL Without Scheme](#url-without-scheme) @@ -163,6 +164,22 @@ use ProtoneMedia\LaravelMixins\Rules\Host; $rule = Host::make(['facebook.com', 'fb.me']); ``` +### In Keys + +Verifies if the given key or index exists in the array. + +```php +use ProtoneMedia\LaravelMixins\Rules\InKeys; + +$rule = new InKeys(['laravel' => 'Laravel Framework', 'tailwindcss' => 'Tailwind CSS framework']); + +// same as + +use Illuminate\Validation\Rules\In; + +$rule = new In(['laravel', 'tailwindcss']); +``` + ### Max Words Passes if the values contains no more words than specified. diff --git a/src/Rules/InKeys.php b/src/Rules/InKeys.php new file mode 100644 index 0000000..bb31d1e --- /dev/null +++ b/src/Rules/InKeys.php @@ -0,0 +1,24 @@ +values = array_keys($values); + } + + public static function make(array $values): self + { + return new static($values); + } +} diff --git a/tests/Rules/InKeysTest.php b/tests/Rules/InKeysTest.php new file mode 100644 index 0000000..76317a1 --- /dev/null +++ b/tests/Rules/InKeysTest.php @@ -0,0 +1,26 @@ + 'foo', + 'b' => 'bar', + 'c' => 'baz', + ]); + + $validator = Validator::make([], ['attribute' => $rule]); + + $this->assertTrue($validator->setData(['attribute' => 'a'])->passes()); + $this->assertFalse($validator->setData(['attribute' => 'd'])->passes()); + $this->assertFalse($validator->setData(['attribute' => 'foo'])->passes()); + } +}