diff --git a/src/LaravelMetrics.php b/src/LaravelMetrics.php index 9d0089c..9ebe003 100644 --- a/src/LaravelMetrics.php +++ b/src/LaravelMetrics.php @@ -523,28 +523,29 @@ protected function generateDateRange($startDate, $endDate) return $dateRange; } - protected function fillEmptyDatesFromCollection(Collection $data): Collection + protected function fillEmptyDatesFromCollection(array $data): array { $dateRange = $this->generateDateRange($this->period[0], $this->period[1]); - $mergedData = []; + $data = collect($data); + $result = []; foreach ($dateRange as $date) { $dataForDate = $data->where('label', $date)->first(); if ($dataForDate) { - $mergedData[] = [ - 'label' => $dataForDate->label, - 'data' => $dataForDate->data + $result[] = [ + 'label' => $dataForDate['label'], + 'data' => $dataForDate['data'] ]; } else { - $mergedData[] = [ + $result[] = [ 'label' => $date, 'data' => $this->emptyDatesData ]; } } - return collect($mergedData); + return $result; } /** @@ -561,7 +562,7 @@ public function metrics(): mixed */ public function trends(): array { - $trendsData = $this->trendsData(); + $trendsData = $this->trendsData()->toArray(); if ($this->fillEmptyDates) { $trendsData = $this->fillEmptyDatesFromCollection($trendsData); @@ -639,10 +640,10 @@ protected function formatPeriod(string $period): string }; } - protected function formatDate(Collection $data): Collection + protected function formatDate(array $data): array { - return $data->map(function ($datum) { - if (!is_numeric($datum['label']) && !DateTime::createFromFormat('Y-m-d',$datum['label'])) { + return array_map(function ($datum) { + if (!is_numeric($datum['label']) && !DateTime::createFromFormat('Y-m-d', $datum['label'])) { return $datum; } @@ -659,7 +660,7 @@ protected function formatDate(Collection $data): Collection } return $datum; - }); + }, $data); } protected function checkDateFormat(array $dates): void