1
I have an order page, let’s take as a base a mercantil, where the person buys 3 sodas each with the value of R $ 6,00 and 2 cookies in the value of R $ 2,00 each.
First I need to multiply these values (3 * 6) and (2 * 2) and then add their results, which would give a total purchase amount of R $ 22,00 as well as bring the name of the customer who made the purchase.
I’m using the Eloquent of Laravel, but I’ve been finding some difficulties in the elaboration of 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();
What is the expected result?
– novic
receive only customer name, sale date and total value
– Carlos Eduardo Silva