Skip to content

Commit d2e45c7

Browse files
authored
Custom filter on specific properties using ApiFilter annotation
When using `ApiFilter` annotation, it seems that you have to set the concerned properties in the annotation itself.
1 parent 25bd64f commit d2e45c7

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

core/filters.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -951,6 +951,27 @@ class Offer
951951
}
952952
```
953953

954+
When using `ApiFilter` annotation, you can specify specific properties for which the filter will be applied:
955+
```
956+
<?php
957+
// api/src/Entity/Offer.php
958+
959+
namespace App\Entity;
960+
961+
use ApiPlatform\Core\Annotation\ApiFilter;
962+
use ApiPlatform\Core\Annotation\ApiResource;
963+
use App\Filter\RegexpFilter;
964+
965+
/**
966+
* @ApiResource
967+
* @ApiFilter(RegexpFilter::class, properties={"email","anOtherProperty"})
968+
*/
969+
class Offer
970+
{
971+
// ...
972+
}
973+
```
974+
954975
You can now enable this filter using URLs like `http://example.com/offers?regexp_email=^[FOO]`. This new filter will also
955976
appear in Swagger and Hydra documentations.
956977

0 commit comments

Comments
 (0)