I am currently creating an array like so
$propertyData[] = array(
'propertyID' => $property->propertyID,
'propertyDepartment' => $property->department,
'displayAddress' => $property->propertyAddress->displayAddress,
'price' => $property->propertyDetails->price
);
I then have a one to many on one of my models, as such, I am adding multiple additional data like so
foreach ($property->propertyImages as $image) {
$propertyData[]['images'] = array(
'imageUrl' => $image->imageUrl,
);
}
The result of the above is something like the following
array:2 [
0 => array:4 [
"propertyID" => "Some Data"
"propertyDepartment" => "Some Data"
"displayAddress" => "Some Data"
"price" => "111111"
]
"images" => array:3 [
0 => array:1 [
"imageUrl" => "Some URL"
]
1 => array:1 [
"imageUrl" => "Some URL"
]
2 => array:1 [
"imageUrl" => "Some URL"
]
]
]
This is nearly what I am after, but not quite. I want the images element to be part of the original array. So what I am after is the following
array:1 [
0 => array:4 [
"propertyID" => "Some Data"
"propertyDepartment" => "Some Data"
"displayAddress" => "Some Data"
"price" => "111111"
"images" => array:3 [
0 => array:1 [
"imageUrl" => "Some URL"
]
1 => array:1 [
"imageUrl" => "Some URL"
]
2 => array:1 [
"imageUrl" => "Some URL"
]
]
]
]
How would I go about achieving this?
Thanks
$property->propertyImagesalready an array? Could you not just assign it like'images' => $property->propertyImages?