Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions content/2.endpoints/2.search.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ Here is a quick look at what you can do:
"relation": "stars",
"type": "max",
"field": "rate",
"alias": "approved_max_rate",
"filters": [
{"field": "approved", "value": true}
]
Expand Down Expand Up @@ -104,6 +105,7 @@ Here is a quick look at what you can do:
| `aggregates.relation` | `string` | X | | The relation you are querying |
| `aggregates.type` | `string` | X | | The type of the aggregates you want to use in: `min`, `max`, `avg`, `sum`, `count` and `exists` |
| `aggregates.field` | `string` | when type is not `exists` or `count` | `*` | The field you want to execute your aggregate on |
| `aggregates.alias` | `string` | | | The name to use for the aggregate column in the response |
| `aggregates.filters` | `array` | | | You can specify all the arguments for the `filters` section |
| **Instructions** | | | | |
| `instructions.name` | `string` | X | | The instruction `uriKey` |
Expand Down Expand Up @@ -416,6 +418,26 @@ The type could be one of these:
For the `exists` and `count` operation you must not specify the field since these aggregates don't base themselves on a column.
::

### Aliases

You may optionally define an alias for your aggregate using the alias method. This allows you to customize the name of the aggregate column in the response, instead of relying on Laravel's default naming.

```json
// (POST) api/posts/search
{
"search": {
"aggregates": [
{
"relation": "comments",
"type": "avg",
"field": "stars",
"alias": "stars_average"
}
]
}
}
```

#### Aggregates filtering

For more complex aggregates, Laravel Rest Api allows you to specify filters. These filters are the same as [the basic ones](/endpoints/search#filters).
Expand Down