Skip to content

Commit 5ac9eaa

Browse files
authored
docs: boolean filter (#2125)
1 parent 3962b58 commit 5ac9eaa

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

laravel/filters.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,33 @@ This allows to query multiple `isbn` values with a `q` query parameter: `/books?
153153
154154
TODO -->
155155

156+
### BooleanFilter
157+
158+
The `BooleanFilter` allows to filter using an `WHERE` clause on a boolean field with (`true`, `false`, `0`, `1`):
159+
160+
```php
161+
// app/Models/Book.php
162+
163+
use ApiPlatform\Laravel\Eloquent\Filter\BooleanFilter;
164+
165+
#[ApiResource]
166+
#[QueryParameter(key: 'published', filter: BooleanFilter::class)]
167+
class Book extends Model
168+
{
169+
use HasUlids;
170+
171+
public function author(): BelongsTo
172+
{
173+
return $this->belongsTo(Author::class);
174+
}
175+
}
176+
```
177+
Examples:
178+
- `/books?published=true`
179+
- `/books?published=1`
180+
- `/books?published=false`
181+
- `/books?published=0`
182+
156183
### PropertyFilter
157184

158185
Note: We strongly recommend using [Vulcain](https://vulcain.rocks) instead of this filter. Vulcain is faster, allows a better hit rate, and is supported out of the box in the API Platform distribution.

0 commit comments

Comments
 (0)