I using laravel api resource for my FRONT-END site.
Actually i using also laravel pagination to handle paginate in FRONT-END.
The api resource structure like this:
{
"data": [...],
"links": [...], // handle pagination
"meta": [...] // handle pagination
}
But i want to send count of query results without considering paginating .For example i paginating database result into 30 pre_page and the all of query result is
200 and i want to send this count to view front-end
I decided to get count of query result and give to resource collection and restructure laravel api resource to this.
{
"data": [...],
"metadata": {
"count": 200
},
"links": [...], // handle pagination
"meta": [...] // handle pagination
}
Also you sould know maybe i want to add another data to this collection. for example conversion rate in addition count to metadata and i don't know how do this.