如何显示价格计算的总计
how to display the total from the price calculation
例如第一行的价格是 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>
您可以将 $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>
例如第一行的价格是 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>
您可以将 $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>