I have a MySQL query which is working fine, but I want to convert it into an Eloquent query, is this possible?
This query will get the sum of quantity by product from all orders and show it's current stock.
Query:
SELECT p.name, SUM(op.quantity) AS quantity, p.stock
FROM `orders` o
JOIN
order_items op
ON op.order_id = o.id
LEFT JOIN products p ON p.id = op.item_id
WHERE o.status = 'Completed'
GROUP BY p.id
ORDER BY p.name;