I have two tables -
table collages - [id, name]
table products - [id, name, collage_id]
I want to get all the collages with the products who has related collage_id.
This is my code
$collages = Collages::all();
foreach($collages as $collage){
$collage['products'] = Product::getByCollageId($collage['id']);
}
And this is the output -
Array
(
[id] => 12
[collage_name] => frida_calo.jpeg
[products] => Array
(
[0] => Array
(
[id] => 11
[name] => couch
[collage_id] => 12
)
)
)
It seems that every iterate the next product remove the previous product. How can I get all the products in an array?