Я пытаюсь умножить цену каждого элемента на количество внутри массива. это запрос, который я получаю с мобильного телефона через API: я использовал dd ($ request-> all ());
array:2 [
9 => "4"
8 => "6"
]
//where(9,8) are the item ids and 4,6 are the quantities
$req = $request->all();
$items= [];
foreach ($req as $key => $value){
$items[] = [
"item_id" =>$key ,
"quantity" =>$value ,
];
}
$ids= [];
foreach ($req as $key => $value){
$ids[] = $key;
}
$qunts = [];
foreach ($req as $key => $value){
$qunts[] = (int)$value;
}
$items = Item::whereIn('id',$ids)->get();
//here I'm trying to mutiply each item price with it's quantity comming from the request
$priceTotal = 0;
foreach($items as $item) {
$subtotal = $item->price * $qunts;
$priceTotal += $subtotal;
}