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