File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed
Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff 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
204233Most of the time, a parameter maps directly to a property on your resource. For example, a
You can’t perform that action at this time.
0 commit comments