Код: Выделить всё
Color
Total
@if ($counts)
@foreach ($counts as $item)
{{ $item->color }}
{{ $item->total }}
@endforeach
@endif
Код: Выделить всё
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', '
Подробнее здесь: [url]https://stackoverflow.com/questions/79756716/calculate-the-sum-total-of-column-values[/url]