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: docs/features/filtering.md
+8-2Lines changed: 8 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,7 @@ weight: 1
5
5
6
6
The `filter` query parameters can be used to add `where` clauses to your Eloquent query. Out of the box we support filtering results by partial attribute value, exact attribute value or even if an attribute value exists in a given array of values. For anything more advanced, custom filters can be used.
7
7
8
-
By default, all filters have to be explicitly allowed using `allowedFilters()`. This method takes an array of strings or `AllowedFilter` instances. An allowed filter can be partial, exact, scope or custom. By default, any string values passed to `allowedFilters()` will automatically be converted to `AllowedFilter::partial()` filters.
8
+
By default, all filters have to be explicitly allowed using `allowedFilters()`. This method takes an array of strings or `AllowedFilter` instances. An allowed filter can be partial, beginsWithStrict, exact, scope or custom. By default, any string values passed to `allowedFilters()` will automatically be converted to `AllowedFilter::partial()` filters.
// $users will contain all users that contain "seb" OR "freek" in their name
32
32
```
33
33
34
+
By passing column name strings to `allowedFilters`, **partial** filters are automatically applied.
35
+
34
36
## Disallowed filters
35
37
36
38
Finally, when trying to filter on properties that have not been allowed using `allowedFilters()` an `InvalidFilterQuery` exception will be thrown along with a list of allowed filters.
37
39
38
40
39
41
## Disable InvalidFilterQuery exception
40
42
41
-
You can set in configuration file to not throw an InvalidFilterQuery exception when a filter is not set in allowedFilter method.
43
+
You can set in configuration file to not throw an InvalidFilterQuery exception when a filter is not set in allowedFilter method. This does **not** allow using any filter, it just disables the exception.
42
44
43
45
```php
44
46
'disable_invalid_filter_query_exception' => true
45
47
```
46
48
47
49
By default the option is set false.
48
50
51
+
## Partial and beginsWithStrict filters
52
+
53
+
By default, all values passed to `allowedFilters` are converted to partial filters. The underlying query will be modified to use a `LIKE LOWER(%value%)` statement. Because this can cause missed indexes, it's often worth considering a `beginsWithStrict` filter instead. This filter will use a `LIKE value%` statement instead.
54
+
49
55
## Exact filters
50
56
51
57
When filtering IDs, boolean values or a literal string, you'll want to use exact filters. This way `/users?filter[id]=1` won't match all users having the digit `1` in their ID.
0 commit comments