I am newbie in Laravel. I am using laravel as a REST End Point, I use Eloquent: API Resources for transforming my data to JSON.
I am using Collection and Resource to parse my data came from my query. So below is the structure of my response:
data:
0
id
name
1
id
name
Now I need to have some categorization in the data, hence I require the data structure to be in below format
data:
24H
0
id
name
1
id
name
7D
0
id
name
1
id
name
I tried couple of ways to accomplish this, the static way I tried for testing was to change the ResourceCollection's toArray method and append the key 24H for the data we get.
But I know that is not correct and generic way.
I would like to know how I can achieve the above response format in generic and extensible manner.
Your help is much appreciated.
Thanks.