skip to Main Content

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

2

Answers


  1. I think you are using wrong with laravel blade php directive

    https://laravel.com/docs/10.x/blade#raw-php

    Login or Signup to reply.
  2. Since you have more than one PHP lines of code, you can use this syntax:

    @php
       $i = 1;
       $yearTotal = 0;
       $futureYearTotal = 0;
    @endphp
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search