can soeone help to modify the json result to another result format.
I have this json
{
"_links": {...},
"total": 10,
"data": [
{
"_links": { ... },
"id": 1,
"name": "John Doe",
"email": "john@doe.com",
"images": [
{
"imageid": 12,
"name": "Trees",
"url":"http://path/of/image.jpg"
},
{
"imageid": 13,
"name": "People",
"url":"http://path/of/image.jpg"
},
]
}
]
}
Then my goal is to achieve this kind of result:
{
"_links": { ... },
"total": 10,
"data": [
{
"_links": { ... }
"id": 1,
"name": "John Doe",
"email": "john@doe.com",
"images": [
{
"12" : {
"name":"Trees",
"url":"http://path/of/image.jpg"
},
"13" : {
"name":"People",
"url":"http://path/of/image.jpg"
}
}
]
}
]
}
SO basically on the second json I want the imageid to be a keyname inside the images object. I would like to collection in laravel instead of looping. something like:
collect($results)->each(function($value, $key){
//code here...
});
Please help. Thanks