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: content/2.endpoints/2.search.md
+22
Original file line number
Diff line number
Diff line change
@@ -58,6 +58,7 @@ Here is a quick look at what you can do:
58
58
"relation": "stars",
59
59
"type": "max",
60
60
"field": "rate",
61
+
"alias": "approved_max_stars",
61
62
"filters": [
62
63
{"field": "approved", "value": true}
63
64
]
@@ -104,6 +105,7 @@ Here is a quick look at what you can do:
104
105
|`aggregates.relation`|`string`| X || The relation you are querying |
105
106
|`aggregates.type`|`string`| X || The type of the aggregates you want to use in: `min`, `max`, `avg`, `sum`, `count` and `exists`|
106
107
|`aggregates.field`|`string`| when type is not `exists` or `count`|`*`| The field you want to execute your aggregate on |
108
+
|`aggregates.alias`|`string`||| The alias given for the aggregate |
107
109
|`aggregates.filters`|`array`||| You can specify all the arguments for the `filters` section |
108
110
|**Instructions**|||||
109
111
|`instructions.name`|`string`| X || The instruction `uriKey`|
@@ -416,6 +418,26 @@ The type could be one of these:
416
418
For the `exists` and `count` operation you must not specify the field since these aggregates don't base themselves on a column.
417
419
::
418
420
421
+
### Aliases
422
+
423
+
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.
424
+
425
+
```json
426
+
// (POST) api/posts/search
427
+
{
428
+
"search": {
429
+
"aggregates": [
430
+
{
431
+
"relation": "comments",
432
+
"type": "avg",
433
+
"field": "stars",
434
+
"alias": "average_stars"
435
+
}
436
+
]
437
+
}
438
+
}
439
+
```
440
+
419
441
#### Aggregates filtering
420
442
421
443
For more complex aggregates, Laravel Rest Api allows you to specify filters. These filters are the same as [the basic ones](/endpoints/search#filters).
0 commit comments