I am trying to merge values together into one collection while I loop.
Here is my current setup
$collection = collect([]);
foreach($array as $item){
$temp = $item->do_something;
!is_null($temp) ? $collection->merge($temp) : null;
}
What $temp can hold is following:
array['records' => $array, 'details' => $array]
Now the closest I got was $array of $temp values but instead I would like to merge all those values into one collection. Instead of array of $temp arrays I would like one collection with Records, and Details.
Thanks
More details what I got visual:
[0]=> ['records' => $array
'details' => $array]
[1]=> ['records' => $array
'details' => $array]
[2]=> ['records' => $array
'details' => $array]
What I would like is to merge all those into one
['records' => $array, 'details' => $array]