I don't know what format you are looking for, but you can group the Collection by any of its (nested) attributes, e.g.
// your existing code
$rows->each(function (array $rowProperties) use (&$meals) {
$mealId = Uuid::uuid1()->toString();
$meals[] = [
'meals' => [
'id' => $mealId,
'meal' => $rowProperties['Måltid'],
'weekdayId' => '',
'planId' => '',
],
'items' => [
'id' => Uuid::uuid1()->toString(),
'mealId' => $mealId,
'planId' => '',
'food' => $rowProperties['Fødevare'],
'grams' => $rowProperties['Mængde (g)'],
'protein' => $rowProperties['Protein (g)'],
'carbs' => $rowProperties['Energi (kcal)'],
'fat' => $rowProperties['Fedt (g)'],
'note' => null,
],
];
})
// grouping
->groupBy('meals.id');
Now you will have a Collection grouped by the UUID, where each group contains the items associated with that meal - it can be further by adding to the Collection pipeline