I need to format the data field of the Laravel API response in order to make it a dictionary. I am using Laravel Resources.
At the moment the result is
{
"data": [
{
"id": 1,
"title": "Qui enim rerum."
},
{
"id": 2,
"title": "Vel praesentium sit."
},
....
],
"links": {
"first": "http://localhost:8000/api/articles?page=1",
"last": "http://localhost:8000/api/articles?page=6",
"prev": null,
"next": "http://localhost:8000/api/articles?page=2"
},
"meta": {
"current_page": 1,
"from": 1,
"last_page": 6,
"path": "http://localhost:8000/api/articles",
"per_page": 5,
"to": 5,
"total": 30
}
}
And I am pretty fine with all the json.
But I want the 'data' field to be a dictionary-like:
"data": {
"1", {
"id": 1,
"title": "Qui enim rerum."
},
"2", {
"id": 2,
"title": "Vel praesentium sit."
},
....
}
Doing so, I can access directly to the item I want without iterate over the array. Is there a way to do this using Laravel Resource (maybe not, but keeping the "links" and "meta")?
Thanks.