diff --git a/README.md b/README.md index 5a7d8d4..3bb6f85 100644 --- a/README.md +++ b/README.md @@ -439,6 +439,7 @@ For convenience, some commonly used regular expression patterns have helper attr ```php #[WhereAlpha('alpha')] #[WhereAlphaNumeric('alpha-numeric')] +#[WhereIn('in', ['value1', 'value2'])] #[WhereNumber('number')] #[WhereUlid('ulid')] #[WhereUuid('uuid')] diff --git a/src/Attributes/WhereIn.php b/src/Attributes/WhereIn.php new file mode 100644 index 0000000..d814ae3 --- /dev/null +++ b/src/Attributes/WhereIn.php @@ -0,0 +1,15 @@ +param = $param; + $this->constraint = implode('|', $constraint); + } +} diff --git a/tests/AttributeTests/WhereAttributeTest.php b/tests/AttributeTests/WhereAttributeTest.php index e962a9b..16c3c71 100644 --- a/tests/AttributeTests/WhereAttributeTest.php +++ b/tests/AttributeTests/WhereAttributeTest.php @@ -59,6 +59,7 @@ public function it_can_apply_shorthand_where() 'param' => '[0-9]+', 'alpha' => '[a-zA-Z]+', 'alpha-numeric' => '[a-zA-Z0-9]+', + 'in' => 'value1|value2', 'number' => '[0-9]+', 'ulid' => '[0-7][0-9A-HJKMNP-TV-Z]{25}', 'uuid' => '[\da-fA-F]{8}-[\da-fA-F]{4}-[\da-fA-F]{4}-[\da-fA-F]{4}-[\da-fA-F]{12}', diff --git a/tests/TestClasses/Controllers/WhereTestController.php b/tests/TestClasses/Controllers/WhereTestController.php index de7178d..846d73f 100644 --- a/tests/TestClasses/Controllers/WhereTestController.php +++ b/tests/TestClasses/Controllers/WhereTestController.php @@ -7,6 +7,7 @@ use Spatie\RouteAttributes\Attributes\Where; use Spatie\RouteAttributes\Attributes\WhereAlpha; use Spatie\RouteAttributes\Attributes\WhereAlphaNumeric; +use Spatie\RouteAttributes\Attributes\WhereIn; use Spatie\RouteAttributes\Attributes\WhereNumber; use Spatie\RouteAttributes\Attributes\WhereUlid; use Spatie\RouteAttributes\Attributes\WhereUuid; @@ -35,6 +36,7 @@ public function myWhereMethod() #[Get('my-shorthands')] #[WhereAlpha('alpha')] #[WhereAlphaNumeric('alpha-numeric')] + #[WhereIn('in', ['value1', 'value2'])] #[WhereNumber('number')] #[WhereUlid('ulid')] #[WhereUuid('uuid')]