startDate = $startDate; $this->endDate = $endDate; } /** * @return \Illuminate\Support\Collection */ public function collection() { return Humidity::whereBetween('created_at', [$this->startDate, $this->endDate]) ->selectRaw('DATE(created_at) as tanggal, AVG(nilai_humidity) as rata_rata_humidity') ->groupBy('tanggal') ->orderBy('tanggal') ->get(); } public function headings(): array { return [ 'No', 'Tanggal', 'Rata-rata Kelembapan', ]; } /** * @param mixed $row */ public function map($row): array { static $number = 0; $number++; return [ $number, $row->tanggal, $row->rata_rata_humidity, ]; } /** * @return array */ public function styles(Worksheet $sheet) { // Apply styles to the header row $sheet->getStyle('A1:C1')->applyFromArray([ 'font' => [ 'bold' => true, 'color' => ['argb' => Color::COLOR_WHITE], ], 'fill' => [ 'fillType' => Fill::FILL_SOLID, 'startColor' => ['argb' => 'FF4CAF50'], ], ]); // Apply borders to all cells $sheet->getStyle('A1:C'.($sheet->getHighestRow())) ->getBorders() ->getAllBorders() ->setBorderStyle(Border::BORDER_THIN) ->setColor(new Color(Color::COLOR_BLACK)); return []; } }