I am trying to calculate the sum of the price of multiple products with their quantities. The request is:
[{"product_id": 14, "quantity": 1}, {"product_id": 18, "quantity": 1}, {"product_id": 15, "quantity": 1}]
I get product_ids [14,18,15] from the above array and with whereIn find the sum:
Product::whereIn('id', $product_ids)->sum("prices");
How can I also consider the quantities while calculating the sum, I can do it by foreach but is there any other solution?