Lomkit / laravel-rest-api

Generate Api in seconds
https://laravel-rest-api.lomkit.com/
MIT License
444 stars 25 forks source link

How to use aggregates in self resource #105

Open ThanhSonITNIC opened 7 months ago

ThanhSonITNIC commented 7 months ago

Description

Stats api as my recommended below or have any other solution?

// (POST) api/posts/search

{
  "search": {
    "aggregates": [
      {
        "type": "count",
        "filters": [
          {"field": "published", "value": true}
        ]
      }
    ]
  }
}

my wish response

{
    "current_page": 1,
    "data": [],
    "from": 1,
    "last_page": 1,
    "per_page": 50,
    "to": 2,
    "total": 2,
    "meta": {
        "count_published": 1 // number of published posts
    }
}
GautierDele commented 7 months ago

Aggregates are meant to be called on models effectively, i'll let this open in order to find a solution