Skip to content

Commit

Permalink
add discussions link to docs
Browse files Browse the repository at this point in the history
  • Loading branch information
abbasudo committed Jun 15, 2024
1 parent ff80d06 commit 4c16c60
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
4 changes: 4 additions & 0 deletions docs/.vuepress/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ export default defineUserConfig({
'upgrade.md',
],
},
{
text: 'Ask a Question',
link: 'https://github.com/abbasudo/laravel-purity/discussions',
},
],
repo: 'abbasudo/laravel-purity',
docsRepo: 'abbasudo/laravel-purity',
Expand Down
26 changes: 23 additions & 3 deletions docs/js-examples/filter.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Examples in this documentation showcase how you can use `qs`.
Find users having 'John' as their first name

`GET /api/users?filters[name][$eq]=John`

```js
const qs = require('qs');
const query = qs.stringify({
Expand All @@ -34,9 +35,11 @@ const query = qs.stringify({

await request(`/api/users?${query}`);
```

Find multiple restaurants with ids 3, 6, 8

`GET /api/restaurants?filters[id][$in][0]=3&filters[id][$in][1]=6&filters[id][$in][2]=8`

```js
const qs = require('qs');
const query = qs.stringify({
Expand All @@ -51,12 +54,16 @@ const query = qs.stringify({

await request(`/api/restaurants?${query}`);
```

#### Complex Filtering
Complex filtering is combining multiple filters using advanced methods such as combining `$and` & `$or`. This allows for more flexibility to request exactly the data needed.

Complex filtering is combining multiple filters using advanced methods such as combining `$and` & `$or`. This allows for
more flexibility to request exactly the data needed.

Find books with two possible dates and a specific author.

`GET /api/books?filters[$or][0][date][$eq]=2020-01-01&filters[$or][1][date][$eq]=2020-01-02&filters[author][name][$eq]=Kai%20doe`

```js
const qs = require('qs');
const query = qs.stringify({
Expand Down Expand Up @@ -85,12 +92,15 @@ const query = qs.stringify({

await request(`/api/books?${query}`);
```

#### Relation Filtering

Relation filtering is filtering on a relation's fields.

Find restaurants owned by a chef who belongs to a 5-star restaurant

`GET /api/restaurants?filters[chef][restaurants][stars][$eq]=5`

```js
const qs = require('qs');
const query = qs.stringify({
Expand All @@ -110,7 +120,13 @@ const query = qs.stringify({
await request(`/api/restaurants?${query}`);
```

::: warning
Relation must be defined in the Laravel model.
Read more about relation filtering at [relations](../advanced/relation) in the advanced section.
:::

#### Complex Relation Filtering

Complex relation filtering is combining multiple relation filters
using advanced methods such as combining `$and` & `$or`.
This allows for more flexibility to request exactly the data needed.
Expand Down Expand Up @@ -142,7 +158,9 @@ await request(`/api/restaurants?${query}`);
```

##### Laravel Example
Add filters to your query manually by passing an array of filters to the `filter()` method.

Implement the same filter manually by passing an array of filters to the `filter()` method.

```php
$params = [
'filters' => [
Expand All @@ -160,4 +178,6 @@ $params = [
];

$restaurants = Restaurant::filter($params)->get();
```
```

Read more about at [params source](../advanced/param) in the advanced section.
3 changes: 3 additions & 0 deletions docs/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ actions:
- text: What is Purity
link: ./introduction
type: secondary
- text: Community
link: https://github.com/abbasudo/laravel-purity/discussions
type: secondary

features:
- title: Simplicity
Expand Down

0 comments on commit 4c16c60

Please sign in to comment.