year, $this->monthNameToNumber($month)); $period = CarbonPeriod::create($date->startOfMonth(), $date->endOfMonth()); $holidays = $yearPeriod->holidays()->pluck("date"); return $this->generateCalendar($period, $holidays); } protected function monthNameToNumber($name): int { return match ($name) { default => CarbonInterface::JANUARY, "february" => CarbonInterface::FEBRUARY, "march" => CarbonInterface::MARCH, "april" => CarbonInterface::APRIL, "may" => CarbonInterface::MAY, "june" => CarbonInterface::JUNE, "july" => CarbonInterface::JULY, "august" => CarbonInterface::AUGUST, "september" => CarbonInterface::SEPTEMBER, "october" => CarbonInterface::OCTOBER, "november" => CarbonInterface::NOVEMBER, "december" => CarbonInterface::DECEMBER, }; } protected function generateCalendar(CarbonPeriod $period, Collection $holidays): array { $calendar = []; foreach ($period as $day) { $calendar[] = [ "date" => $day->toDateString(), "dayOfMonth" => $day->translatedFormat("j"), "dayOfWeek" => $day->translatedFormat("D"), "isToday" => $day->isToday(), "isWeekend" => $day->isWeekend(), "isHoliday" => $holidays->contains($day), "vacations" => $this->getVacationsForDay($day), ]; } return $calendar; } protected function getVacationsForDay(CarbonInterface $day): Collection { return Vacation::query() ->whereDate("date", $day) ->whereRelation("vacationRequest", "state", VacationRequestState::APPROVED->value) ->pluck("user_id"); } }