I have a page of orders, we will take as base a mercantile, where the person buys 3 soft drinks each with the value of $ 6.00 and 2 cookies in the amount of $ 2.00 each.
I first need to multiply these values (3 * 6) and (2 * 2) and then add their results, which would give a total purchase value of $ 22.00 as well as bring the name of the customer who made the purchase.
I'm using Laravel's Eloquent, but I've been finding some difficulties in crafting the query, if you can help me, follow the code and the image of the relationship
$vendas = Venda::where('data', date('Y-d-m'))
->join('clientes', 'vendas.cliente_id', '=', 'clientes.id')
->join('produtos_venda', 'vendas.id', '=', 'produtos_venda.venda_id')
->select('vendas.*', 'clientes.nome as nome_cliente', 'produtos_venda.quantidade', 'produtos_venda.valor')
->sum('produtos_venda.valor * produtos_venda.quantidade as valor_total')->get();