Merhaba kolay gelsin, aşağıda ki aynı çıkış fişi üzerinde isimleri aynı olan örneğin TURKISH COFFEE CLASSIC 250 GRAMS, adet sayılarını toplatmak ve tekrarlanan ürünleri, tek ürün adı toplam adet, şeklinde listelemek istiyorum bunu nasıl yapabilirim. bu konuda yardımcı olabilirseniz sevinirim, selamlar
controller kodu
$products = Output::where('output_number', $id)->get();
$items = [];
foreach ($products as $product) {
$items[] =
[
'company_name' => $product->company->name,
'output_number' => $product->output_number,
'name' => $product->products->name,
'qty' => $product->qty,
'price' => $product->price,
'discount' => $product->discount,
'notes' => $product->notes,
];
};
return $items;
Ekran Çıktısı
[
{
company_name: "SALIM",
output_number: 201900053,
name: "TURKISH COFFEE CLASSIC 250 GRAMS",
qty: 2,
price: 1.75,
discount: null,
notes: []
},
{
company_name: "SALIM",
output_number: 201900053,
name: "TURKISH COFFEE CLASSIC 250 GRAMS",
qty: 5,
price: 1.75,
discount: null,
notes: []
},
{
company_name: "SALIM",
output_number: 201900053,
name: "Turkish Delight With Pistachio 115 GRAMS",
qty: 10,
price: 0.55,
discount: null,
notes: []
}
]