You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: laravel/filters.md
+38Lines changed: 38 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -44,6 +44,24 @@ final class EqualsFilter implements FilterInterface
44
44
45
45
You can create your own filters by implementing the `ApiPlatform\Laravel\Eloquent\Filter\FilterInterface`. API Platform provides several eloquent filters for a RAD approach.
46
46
47
+
### Parameter for Specific Operations
48
+
49
+
To defines a parameter for only a `GetCollection` operation, you can do the following:
50
+
51
+
```php
52
+
// app/Models/Book.php
53
+
54
+
use ApiPlatform\Laravel\Eloquent\Filter\EqualsFilter;
55
+
use ApiPlatform\Metadata\ApiResource;
56
+
use ApiPlatform\Metadata\QueryParameter;
57
+
58
+
#[ApiResource]
59
+
#[GetCollection(parameters: ['name' => new QueryParameter(key: 'name', filter: EqualsFilter::class)])]
60
+
class Book extends Model
61
+
{
62
+
}
63
+
```
64
+
47
65
### Parameter Validation
48
66
49
67
You can add [validation rules](https://laravel.com/docs/validation) to parameters within the `constraints` attribute:
@@ -86,6 +104,26 @@ class Book extends Model
86
104
87
105
The documentation will output a query parameter per property that applies the `PartialSearchFilter` and also gives the ability to sort by name and ID using: `/books?name=search&order[id]=asc&order[name]=desc`.
88
106
107
+
### Filtering on Specific Properties Only
108
+
109
+
To enable partial search filtering and sorting on specific properties like `name` and `description`:
110
+
111
+
```php
112
+
// app/Models/Book.php
113
+
114
+
use ApiPlatform\Laravel\Eloquent\Filter\PartialSearchFilter;
115
+
use ApiPlatform\Laravel\Eloquent\Filter\OrderFilter;
0 commit comments