whereIn('outlet_id', array_keys($outlets)) ->get() ->groupBy('channel'); $data = []; foreach (OrderChannel::cases() as $channel) { $channelOrders = $orders[$channel->value] ?? collect(); $total = $channelOrders->sum('total'); $data[] = $total; $this->channels[] = $channel->label(); } $this->revenues = $data; // random colors $count = count(OrderChannel::cases()); $this->backgroundColors = randomColors($count, 0.2); $this->borderColors = randomColors($count, 1.0); } public function render() { return view('livewire.chart.channel-revenue'); } }