I have this foreach loop:
my $items looks like this:
array:2 [▼
0 => array:3 [▼
"variant_id" => "393c6c70-8cb7-11e8-815a-f9c70a1fbe8e"
"name" => "Medicine 1"
"quantity" => "1"
]
1 => array:3 [▼
"variant_id" => "8a80d340-e0c1-11e8-86a4-3b06d2b50e37"
"name" => "Medicine 2"
"quantity" => "1"
]
]
Now, in my foreach, I compare the variant_id to my database and get the points from that database and multiply it by the quantity of the Medicines.
points for Medicine 1 is = 50
points for Medicine 2 is = 20
so it should be 50(medicine 1 points) multiplied by 1 (quantity of medicine 1) and
20 x 1 (medicine 2) and then the sum of both which should be equal to 70. But when I dd($sum) what I get is 50 which is only for medicine 1.
$sum = 0;
foreach ($items as $variants) {
$id = $variants['variant_id'];
$quantity = $variants['quantity'];
$find = Activity::where('variant_id', $id)->first();
$act_points = $find->points * $quantity;
$sum += $act_points;
dd($sum);
}
What am I missing here?
dd($sum);afterforeach.