i want to sum the mark variable on blade file. i don't have the line total field on table in database. i find the sum qty and price in line total, but i want to sum all line total.
<?php
$sl = 1;
?>
<tbody>
@foreach($qInvoice as $sInvoice)
<tr>
<td>{{$sl++}}</td>
<td>{{$sInvoice->catName}}</td>
<td>{{$sInvoice->proName}}</td>
<td>{{$sInvoice->qty}}</td>
<td>{{$sInvoice->meName}}</td>
<td class="text-right">{{$sInvoice->price}}/-</td>
<td class="text-right">{{$sInvoice->price * $sInvoice->qty}}/-</td>
<?php
$total = 0;
$lineTotal = $sInvoice->price * $sInvoice->qty;
$total+=$lineTotal;
?>
</tr>
@endforeach
</tbody>
<tfoot>
<tr>
<td colspan="5"></td>
<td class="text-right">Total</td>
<td class="text-right">{{$total}}/-</td>
</tr>
</tfoot>
</table>
i want to sum the all line total in total field without use of controller
Don't make the sum in the view, do it in the controller, for example:
$qInvoice->transform(function($sInvoice) {
$sInvoice->line_total = $sInvoice->qty * $sInvoice->price;
return $sInvoice;
});
$total = $qInvoice->sum($line_total);
And return the view with $total and $qInvoice!