dongse5528 2018-12-10 14:17
浏览 103
已采纳

如何在laravel视图中添加子项总计以获得groupitem总计

I am working on a trial balance page where I want am displaying totals of subgroup items. I want to display a group total. However, I am using {{ }} in the views to display the totals which are coming from the controller

@foreach($sage_paylater_staging as $sg)
 @if( $sg->credit_code == $ledgers->id && $sg->credit_code != '')
    {{ number_format($sg->amount, 2) }}
@endif
@endforeach

This is a code for the subitem total. I want to add the various subitems i.e the amount in the {{ }} and display a total in my group. How could I achieve this?

I have searched numerous websites but there is no way in which I could add the values in the {{ }} in the view. Could anyone help me out?

  • 写回答

1条回答

  • dpp78272 2018-12-10 14:36
    关注

    Something like:

    @php $total = 0; @endphp
    @foreach($sage_paylater_staging as $sg)
        @if( $sg->credit_code == $ledgers->id && $sg->credit_code != '')
            @php $total += $sg->amount; @endphp
            {{ number_format($sg->amount, 2) }}
        @endif
    @endforeach
    {{number_format($total, 2)}}
    

    But ideally you'd do that logic in your controller and pass the total as a var to the view.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 matlab计算中误差
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊