Skip to content

Commit a93d389

Browse files
committed
feat: allow Parameter attributes on properties
1 parent 9971f4e commit a93d389

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

core/filters.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,35 @@ This configuration allows clients to filter events by date ranges using queries
199199
- `/events?date[startDate][after]=2023-01-01`
200200
- `/events?date[endDate][before]=2023-12-31`
201201

202+
### Declaring Parameters on Properties
203+
204+
You can also declare parameters directly on entity properties using `#[QueryParameter]` or
205+
`#[HeaderParameter]` attributes. This keeps your parameter definition close to the property it
206+
affects:
207+
208+
```php
209+
<?php
210+
// api/src/Entity/Book.php
211+
namespace App\Entity;
212+
213+
use ApiPlatform\Doctrine\Orm\Filter\PartialSearchFilter;
214+
use ApiPlatform\Metadata\ApiResource;
215+
use ApiPlatform\Metadata\HeaderParameter;
216+
use ApiPlatform\Metadata\QueryParameter;
217+
218+
#[ApiResource]
219+
class Book
220+
{
221+
#[QueryParameter(key: 'search', filter: new PartialSearchFilter())]
222+
private string $title = '';
223+
224+
#[HeaderParameter(key: 'API-Key', description: 'API authentication key')]
225+
public string $apiKey = '';
226+
}
227+
```
228+
229+
Parameters declared on properties are automatically applied to all operations on the resource.
230+
202231
### Filtering a Single Property
203232

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

0 commit comments

Comments
 (0)