Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

danny620's avatar

Help needed merging collections

Hello,

I have 3 different tables that have different columns but all of them have some identical columns i.e

solar_installations

id | property_id | address_line_1 | town |solar_manufacturer_id | model ...

inverter_installations

id | property_id | address_line_1 | town |inverter_manufacturer_id | model ...

energy_storage_installations

id | property_id | address_line_1 | town |energy_storage_manufacturer_id | model ...

What I would like to do is build a view that can merge all this information together

0 likes
1 reply
STEREOH's avatar

You can pass your 3 collections to your view and make 3 foreach in your view

return view('your-view', compact('solarInstalation ','inverterInstallations ','energyStorageInstallation '));

since your tables have some different columns I would recomend this way, so you can display your informations differently based on what items you are cycling through.

or

You can merge your collection before you pass it to your view.

$solarInstalation = Model1::all();
$inverterInstallations = Model2::all();
$energyStorageInstallation = Model3::all();

$mergedInstallations = $solarInstalation->merge($inverterInstallations->merge($energyStorageInstallation ));

return view('your-view', compact('mergedInstallations')]);

Please or to participate in this conversation.