I need to join to separate arrays, I am working with Laravel 5.3 Collections. I have two separate objects. One object I am getting distance matrix from google maps between cities and street address. The end responses looks like this for example:
[{"distance":"14.0 km"},{"distance":"85.6 km"},{"distance":"15.9 km"}]
I have another response which lists the stores. The distance matrix above is relevant to each store. The store response looks like this:
{
"0":{
"id":3,
"user_id":2,
"brand_id":"2",
"type":"store",
"name":"Store One"
},
"4":{
"id":6,
"user_id":2,
"brand_id":"2",
"type":"store",
"name":"Store Two"
},
"6":{
"id":9,
"user_id":2,
"brand_id":"2",
"type":"store",
"name":"Store Three"
}
}
I need to join each
distance item into each store but I am having trouble combining the both. Basically I need the array to look like this:
{
"0":{
"id":3,
"user_id":2,
"brand_id":"2",
"type":"store",
"name":"Store One",
"distance":"14.0 km"
},
"4":{
"id":6,
"user_id":2,
"brand_id":"2",
"type":"store",
"name":"Store Two",
"distance":"85.6 km"
},
"6":{
"id":9,
"user_id":2,
"brand_id":"2",
"type":"store",
"name":"Store Three",
"distance":"15.9 km"
}
}
Any help or assistance would be greatly appreciated.