Zusammenführen von zwei Laravel -Kollektionen beibehalten der ursprünglichen Schlüssel
$material_grp1 = Batch::findOrFail($batch_id)->batchdetails->mapWithKeys(function($item) {
return [
$item->material_id => $item
];
});;
$material_grp2 = Batch::with('productoutput.productoutputdetails.packsizes')
->find($batch_id)->productoutput->productoutputdetails
->mapWithKeys(function($item) {
return [
$item->packsizes->material_id => $item
];
});
$material_grp = $material_grp1->union($material_grp2);
Irfan