当我在laravel的刀片中使用foreach时,last()或end()不起作用

时间:2018-08-02 08:26:46

标签: php laravel-5.4

end()last()无效...该怎么办?

@foreach($students as $student)

@foreach($payment_heads as $payment_head)

      <td>

      @foreach ($student->payment_detail as $payment_detail_one)


           @if($payment_detail_one->payment_head_id==$payment_head->id)
              <?php

                $total=$total+$payment_detail_one->amount;

              ?>

              @if($payment_detail_one === end($$student->payment_detail)) 
             {{$payment_detail_one->amount}}
             @endif

          @endif

      @endforeach
  </td>
  @endforeach
 @endforeach

1 个答案:

答案 0 :(得分:0)

请参阅文档https://laravel.com/docs/5.5/blade#the-loop-variable
end($$student->payment_detail)用双$$错了
你可以用这个

@foreach($students as $student)
    @foreach($payment_heads as $payment_head)
        <td>
            @foreach ($student->payment_detail as $payment_detail_one)
                @if($payment_detail_one->payment_head_id==$payment_head->id)

                    <?php
                        $total = $total + $payment_detail_one->amount;
                    ?>

                    @if ($loop->last)
                        {{$payment_detail_one->amount}}
                    @endif

                @endif
            @endforeach
        </td>
    @endforeach
@endforeach