我的控制器:
$table = CashBook::select(
DB::raw('DATE(created_at) as date'),
DB::raw('SUM(amountOut) as dr'),
DB::raw('SUM(amountIN) as cr')
)->groupBy('date')
->get();
return view('cashbook.cashbook')->with(['table' => $table]);
我想要实施的表格:
@foreach($table as $row)
<tr>
<td>{{date('d/m/Y', strtotime($row->date))}}</td>
<td>TK. {{number_format($row->cr,2)}}</td>
<td>TK. {{number_format($row->dr,2)}}</td>
@php
$tbalance = $row->cr - $row->dr;
@endphp
<td>TK. {{number_format($tbalance,2)}}</td>
</tr>
@endforeach
我正在尝试平衡借记和信用。但我无法在数组中取<td>TK. {{number_format($tbalance,2)}}</td>
并将当前余额与前一个相加。