select('outlet_id', DB::raw('SUM(total) as total_revenue')) ->whereIn('outlet_id', array_keys($outlets)) ->groupBy('outlet_id') ->pluck('total_revenue', 'outlet_id'); $this->outlets = array_values($outlets); $this->revenues = collect($outlets)->map(fn ($name, $id) => $revenues[$id] ?? 0)->values()->toArray(); // random colors $count = count($this->outlets); $this->backgroundColors = randomColors($count, 0.2); $this->borderColors = randomColors($count, 1.0); } public function render() { return view('livewire.chart.outlet-revenue'); } }