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
{{ message }}
This repository was archived by the owner on Feb 17, 2023. It is now read-only.
This package supports the specification of [JSON API Fetching of Filtered Resources](http://jsonapi.org/format/1.0/#fetching-filtering). Filtering allows requests to remove certain resources not required.
4
+
5
+
# Using Filter Parameter
6
+
7
+
Per the specification, the client is able to request for the inclusion of related resources through the following HTTP request:
8
+
9
+
```http
10
+
GET /api/posts?filter[approved]=1 HTTP/2.0
11
+
Accept: application/vnd.api+json
12
+
```
13
+
14
+
However, by default, this package denies filtering attributes via parameter and would throw the follow error message.
15
+
16
+
```json
17
+
{
18
+
"errors": [
19
+
{
20
+
"title": "Filter should contain only allowed values.",
21
+
"source": {
22
+
"parameter": "filter"
23
+
}
24
+
}
25
+
]
26
+
}
27
+
28
+
```
29
+
30
+
To allow certain attributes to be filtered using request parameters, it must be manually enabled through the resource's `Validators.php` file.
31
+
32
+
```php
33
+
namespace App\JsonApiV1\Posts;
34
+
35
+
class Validators extends AbstractValidatorProvider
36
+
{
37
+
protected $allowedFilteringParameters = [
38
+
'approved'
39
+
];
40
+
41
+
/* Your code here ...*/
42
+
}
43
+
44
+
```
45
+
46
+
And then to put the filtering into action, you add the following part to your `Adapter.php` file.
47
+
48
+
```php
49
+
class Adapter extends AbstractAdapter
50
+
{
51
+
/**
52
+
* @param $query
53
+
* @param Collection $filters
54
+
* @return mixed
55
+
*/
56
+
protected function filter($query, Collection $filters)
57
+
{
58
+
foreach ($filters as $filter_key => $filter_value) {
Copy file name to clipboardExpand all lines: docs/fetching/inclusion.md
+4-5Lines changed: 4 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -1,10 +1,9 @@
1
-
# Inclusion
2
1
3
-
##Introduction
2
+
# Introduction
4
3
5
4
This package supports the specification of [JSON API Inclusion of Related Resources](http://jsonapi.org/format/1.0/#fetching-includes). This allows you to load all the data of the specified resources that is bounded by relationship.
6
5
7
-
###Using Include Parameter
6
+
# Using Include Parameter
8
7
9
8
Per the specification, the client is able to request for the inclusion of related resources through the following HTTP request:
10
9
@@ -45,14 +44,14 @@ class Validators extends AbstractValidatorProvider
45
44
```
46
45
47
46
48
-
###Auto Inclusion
47
+
# Auto Inclusion
49
48
50
49
It is possible to force the inclusion of certain related resources; displaying it even when the client did not specify the related resource in the include parameter. To enable the automatic inclusion of resources, edit the resource's `Schema.php` file.
0 commit comments