I have a table in my blade page,
<table>
<thead>
<tr>
<th>Color</th>
<th>Total</th>
</tr>
</thead>
<tbody>
@if ($counts)
@foreach ($counts as $item)
<tr>
<td>{{ $item->color }}</td>
<td>{{ $item->total }}</td>
</tr>
@endforeach
@endif
</tbody>
</table>
I want to show the sum total of the column Total. I googled for the solution but all suggest to use server side sum function. Is it possible to do it in blade page?
public function get_color_distribution(Request $request)
{
$date_from = Carbon::parse($request->input('n_from_date'))->startOfDay();
$date_to = Carbon::parse($request->input('n_to_date'))->endOfDay();
$counts = Production::join('finishes', 'finishes.id', '=', 'productions.color')
->select(
DB::raw('count(*) as total'),
'finishes.description as color'
)
->whereDate('productions.created_at', '>=', $date_from)
->whereDate('productions.created_at', '<=', $date_to)
->groupBy('finishes.description')
->get();
return view('admin.reports.r_colors_gen', compact(
'counts',
'date_from',
'date_to'
));
}
If I need to do it in server side how to get the total sum of DB::raw('count(*) as total') value?