hi, i got a query but it's not summing well the "kmsTotais" , how do i fix this ? and make it to work? i yesterday asked how to do the sum and subtraction in elloquent to then try to pass it onto the selectraw like i did with abastecimento, but it didnt work, please help fix this , thanks
$totalEurosAbastecimento = $quilometragem->sum('abastecimento_euros');
$totalLitrosAbastecimento = $quilometragem->sum('abastecimento_litros');
$totalrep = $valor->sum('reparacoes.valor');
$data = DB::table("reparacoes")
->select(Reparacoes::raw("reparacoes.matricula,data_ne, $totalLitrosAbastecimento as totalLitrosAbastecimento,
$totalEurosAbastecimento AS totalEurosAbastecimento, $totalrep as totalrep,SUM(formulario.kmfim-formulario.quilometragem) AS kmsTotais"))
->leftJoin('formulario', 'reparacoes.matricula', '=', 'formulario.matricula')
->leftJoin('viaturas', 'reparacoes.matricula', '=', 'viaturas.matricula')
->orderBy("reparacoes.matricula")
->groupBy(DB::raw("reparacoes.matricula"))
->get();
//blade
@foreach ($data as $item)
<tr>
<td>{{ $item->matricula }}</td>
<td>{{ $item->totalrep }}</td>
<td>{{ $item->data_ne }}</td>
<td>{{ $item->kmsTotais }}</td>
<td>{{ $item->totalLitrosAbastecimento }}</td>
<td>{{ $item->totalEurosAbastecimento }}</td>
</tr>
@endforeach
note: quilometragem exists both in formulario ,viaturas and reparacoes table