Search code examples
phplaravellaravel-blade

syntax error, unexpected token "@" (View: /data/sites/web/admin/report/rec_revenue.blade.php


I am Using Laravel and my code was working fine i don't know if this error is because of server or something else. but i guess in blade template it is having trouble converting @php to i would be happy if you will guide me my code look like this

<tbody>
@foreach ($arrData as $k => $data)
@php($i = 1)
@php($yearTotal = 0)
@php($futureYearTotal = 0)
@foreach ($data as $k2 => $yd)
   <tr>
   <td><h6><span class="badge bg-light">{{$k}} {{ $k2 }}</span></h6></td>
   <td class="total-amount" align="right">{{ number_format($yd['total']??0, 2, ',', ' ') }}{{ $yd['currency'] }}</td>
   </tr>
@php($yearTotal += $yd['total'])
@endforeach
@endforeach
</tbody>

enter image description here


Solution

  • Since you have more than one PHP lines of code, you can use this syntax:

    @php
       $i = 1;
       $yearTotal = 0;
       $futureYearTotal = 0;
    @endphp