Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions core/filters.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,35 @@ This configuration allows clients to filter events by date ranges using queries
- `/events?date[startDate][after]=2023-01-01`
- `/events?date[endDate][before]=2023-12-31`

### Declaring Parameters on Properties

You can also declare parameters directly on entity properties using `#[QueryParameter]` or
`#[HeaderParameter]` attributes. This keeps your parameter definition close to the property it
affects:

```php
<?php
// api/src/Entity/Book.php
namespace App\Entity;

use ApiPlatform\Doctrine\Orm\Filter\PartialSearchFilter;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\HeaderParameter;
use ApiPlatform\Metadata\QueryParameter;

#[ApiResource]
class Book
{
#[QueryParameter(key: 'search', filter: new PartialSearchFilter())]
private string $title = '';

#[HeaderParameter(key: 'API-Key', description: 'API authentication key')]
public string $apiKey = '';
}
```

Parameters declared on properties are automatically applied to all operations on the resource.

### Filtering a Single Property

Most of the time, a parameter maps directly to a property on your resource. For example, a
Expand Down
Loading