【问题标题】:how to display the total from the price calculation如何从价格计算中显示总计
【发布时间】:2021-03-23 08:35:00
【问题描述】:

例如第一行的价格是 2,580,000 第二行 950,000 好吧,我想显示所有价格的总和为 3530000,这是我的视图代码:

@forelse ($bookings as $booking)
                                @php
                                    $check_out= date_create($booking['check_out']);
                                    $check_in = date_create($booking['check_in']);
                                    $calculate = date_diff($check_out, $check_in);
                                    $day = $calculate->format("%a");
                                    $price = $day * $booking->room->price;
                                @endphp
                                <tbody>
                                    <th>{{ $loop->iteration + $bookings->firstItem() - 1 . '.' }}</th>
                                    <td><u>{{ $booking->booking_code }}</u></td>
                                    <td>
                                        <span class="badge badge-light">{{ "Rp. " . number_format($price, 0,',','.') }}<span>
                                    </td>
                                </tbody>
                            @empty
                                <tbody>
                                    <tr>
                                        <th colspan="3" style="color: red; text-align: center;">Data Empty!</th>
                                    </tr>
                                </tbody>
                            @endforelse
                            <tfoot>
                                <tr>
                                    <th>TOTAL</th>
                                    <td></td>
                                    <td>{{ $price + $price }}</td>
                                </tr>
                            </tfoot>

【问题讨论】:

    标签: php laravel laravel-7


    【解决方案1】:

    您可以将$price$total 变量相加并在以后使用它们。

    @php
        ...
        $price = $day * $booking->room->price;
        $total = ($total ?? 0) + $price;
    @endphp
    
    <tfoot>
        <tr>
            <th>TOTAL</th>
            <td></td>
            <td>{{ $total }}</td>
        </tr>
    </tfoot>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-01-27
      • 2021-05-20
      • 1970-01-01
      • 1970-01-01
      • 2015-10-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多