Laravel: Soma inside the foreach

0

Good afternoon, people.

I have foreach on my blade and would like to add one of the fields.

@foreach($occupations as $o)
<tr>
    <td>{{ $o->invoiceId }}</td>
    <td>{{ date('m/Y', strtotime($o->date_invoice)) }}</td>
    <td>{{ date('d/m/Y', strtotime($o->date_pay)) }}</td>
    <td>{{ balance($o->date_pay, $o->date_payment, $o->value, $o->invoiceUfir)[0] }}</td>
    <td>{{ balance($o->date_pay, $o->date_payment, $o->value, $o->invoiceUfir)[1] }}</td>
    <td>{{ balance($o->date_pay, $o->date_payment, $o->value, $o->invoiceUfir)[2] }}</td>
    <td>{{ balance($o->date_pay, $o->date_payment, $o->value, $o->invoiceUfir)[3] }}</td>
    <td>{{ dateFormat($o->date_payment) }}</td>
    <td>{{ number_format($o->value, 2, ',', '.') }}</td>
    <td>{{ balance($o->date_pay, $o->date_payment, $o->value, $o->invoiceUfir)[4] }}</td>
</tr>
@endforeach

This is my Blade.

I want to add the last <td>{{ balance($o->date_pay, $o->date_payment, $o->value, $o->invoiceUfir)[4] }}</td> to show in Foot.

Thank you in advance.

    
asked by anonymous 12.06.2018 / 18:11

1 answer

0

Resolved.

I made a foreach on the Controller of the view doing the sum.

$sum = 0;
foreach($occupations as $o):
    $sum += balance($o->date_pay, $o->date_payment, $o->value, $o->invoiceUfir)[4];
endforeach;

And in Blade I just called the variable $sum .

    
12.06.2018 / 19:41