Level 1
try to merge all three tables data with
$step2 = array_merge($table1data,$table2data);
$final= array_merge($step2,$table3data);
or if you are using relationships btw them then use the with() method in query
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Sorry if this in an obvious question, I'm trying to achieve the below result json from a function within a controller, the data will come from 3 separate tables, property, units, images.
I'm not sure how to approach this, any help will be greatly appreciated.
{
"property": {
"id": "1",
"address": "123 Street1",
"units": [{
"unitid": "1",
"propid": "1",
"name": "suite 1",
"size": 500
},
{
"unitid": "2",
"propid": "1",
"name": "suite 2",
"size": 200
},
{
"unitid": "3",
"propid": "1",
"name": "suite 3",
"size": 340
}
],
"images": [{
"imageid": "1",
"propid": "1",
"src": "Images/Sun.png",
"name": "sun1"
},
{
"imageid": "2",
"propid": "1",
"src": "Images/Sun2.png",
"name": "sun2"
},
{
"imageid": "3",
"propid": "1",
"src": "Images/Sun3.png",
"name": "sun3"
}
]
}
}
try to merge all three tables data with
$step2 = array_merge($table1data,$table2data);
$final= array_merge($step2,$table3data);
or if you are using relationships btw them then use the with() method in query
Please or to participate in this conversation.