|null */ private ?array $byDate = null; public function ulspPence(string $date): ?int { $row = $this->byDate()[$date] ?? null; return $row === null ? null : (int) $row->ulsp_pence; } public function ulsdPence(string $date): ?int { $row = $this->byDate()[$date] ?? null; return $row === null ? null : (int) $row->ulsd_pence; } /** @return array Sorted ascending. */ public function allDates(): array { return array_keys($this->byDate()); } /** @return array */ private function byDate(): array { if ($this->byDate !== null) { return $this->byDate; } $rows = DB::table('weekly_pump_prices') ->orderBy('date') ->get(['date', 'ulsp_pence', 'ulsd_pence']); $map = []; foreach ($rows as $r) { $map[(string) $r->date] = $r; } $this->byDate = $map; return $map; } }