Skip to content

Commit de314ae

Browse files
committed
docs
1 parent cf61d6f commit de314ae

File tree

2 files changed

+46
-9
lines changed

2 files changed

+46
-9
lines changed

docs/laravel.md

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -166,23 +166,28 @@ BooleanDateTime::make('isDeleted')
166166
The Laravel integration provides a number of filters for use in your Eloquent
167167
resources.
168168

169-
### Where
169+
### Where Filters
170170

171171
```php
172172
Where::make('name');
173173
Where::make('id')->commaSeparated();
174174
Where::make('isConfirmed')->asBoolean();
175-
Where::make('score')->asNumeric();
176-
WhereBelongsTo::make('user');
177-
Has::make('hasComments');
178-
WhereHas::make('comments');
179-
WhereDoesntHave::make('comments');
180-
WhereNull::make('draft')->property('published_at');
181-
WhereNotNull::make('published')->property('published_at');
182-
Scope::make('withTrashed');
175+
WhereBelongsTo::make('author')->relationship('user');
176+
WhereExists::make('comments');
177+
WhereCount::make('commentCount')->relationship('comments');
178+
WhereHas::make('tags');
179+
WhereNull::make('draft')->column('published_at');
180+
WhereNotNull::make('published')->column('published_at');
181+
Scope::make('withTrashed')->asBoolean();
183182
Scope::make('trashed')->scope('onlyTrashed');
184183
```
185184

185+
### Boolean Filters
186+
187+
`EloquentResource` implements
188+
`Tobyz\\JsonApiServer\\Resource\\SupportsBooleanFilters`, so you can combine
189+
filters with `[and]`, `[or]`, and `[not]` groups without extra configuration.
190+
186191
## Sort Fields
187192

188193
The Laravel integration provides a number of sort fields for use in your

docs/list.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,38 @@ GET /posts?filter[name]=Toby
218218
GET /posts?filter[name][]=Toby&filter[name][]=Franz
219219
```
220220

221+
### Boolean Filters
222+
223+
By default it is assumed that each filter applied to the query will be combined
224+
with a logical `AND`. When a resource implements
225+
`Tobyz\\JsonApiServer\\Resource\\SupportsBooleanFilters` you can express more
226+
complex logic with `AND`, `OR`, and `NOT` groups.
227+
228+
Boolean groups are expressed by nesting objects under the `filter` parameter.
229+
You may use either associative objects or indexed lists of clauses. Each clause
230+
can be another filter or another boolean group.
231+
232+
```http
233+
GET /posts
234+
?filter[and][0][status]=published
235+
&filter[and][1][or][0][views][gt]=100
236+
&filter[and][1][or][1][not][status]=archived
237+
```
238+
239+
In this request every result must be published, and it must also either have
240+
more than 100 views or it is not archived.
241+
242+
```http
243+
GET /posts
244+
?filter[or][0][status]=draft
245+
&filter[or][1][status]=published
246+
&filter[or][1][not][comments]=0
247+
```
248+
249+
This request returns drafts, or posts that are published and have comments. The
250+
second example also shows that in certain cases you can omit `[and]` groups and
251+
numeric indices; sibling filters at the same level default to `AND` behaviour.
252+
221253
### Writing Filters
222254

223255
To create your own filter class, extend the `Tobyz\JsonApiServer\Schema\Filter`

0 commit comments

Comments
 (0)