repository->retrieveElectricity(); $gas = $this->repository->retrieveGas(); $now = Carbon::now(); $eNow = $electricity->first( fn ($item) => $item->startDate instanceof Carbon && $item->startDate->gte($now->copy()->subHour()) && $item->startDate->lte($now) ); $eCheapest = $electricity->where('totalPriceTaxIncluded', $electricity->min('totalPriceTaxIncluded'))->first(); $eDurable = $electricity->where('sustainabilityScore', $electricity->max('sustainabilityScore'))->first(); $ePriciest = $electricity->where('totalPriceTaxIncluded', $electricity->max('totalPriceTaxIncluded'))->first(); $gNow = $gas->first( fn ($item) => $item->startDate instanceof Carbon && $item->startDate->gte($now->copy()->startOfDay()) && $item->startDate->lte($now) ); return new DashboardData( $eNow, $eCheapest, $eDurable, $ePriciest, $gNow, ); } }