first(); if ($closedDays) { return $closedDays->id; } // Create if does not exists yet $closedDays = ClosedDay::create([ 'restaurant_id' => $tenantId, 'meta_value' => [ 'dates' => [], 'full_dates' => [] ], ]); return $closedDays->id; } //public static function getItems(AppSettingsRequest $request, $tenantId) public static function getItems(Request $request, $tenantId) { // Only one per tenant $closedDaysId = ClosedDay::getId($tenantId); $closedDays = ClosedDay::find($closedDaysId); // Return both arrays return [ 'dates' => $closedDays->dates ?? [], 'full_dates' => $closedDays->full_dates ?? [] ]; } /** * Get only the dates array (for backward compatibility) * @return array */ public function getDatesArray() { return $this->dates ?? []; } /** * Get only the full_dates array * @return array */ public function getFullDatesArray() { return $this->full_dates ?? []; } /** * Check if a date is a full day (restaurant is full, not just closed) * @param string $date * @return bool */ public function isFullDay($date) { $fullDates = $this->full_dates; return is_array($fullDates) && in_array($date, $fullDates); } /** * Check if a date is closed (either manually closed or full) * @param string $date * @return bool */ public function isClosedDay($date) { $dates = $this->dates; return is_array($dates) && in_array($date, $dates); } /** * Remove closed days from the array * @param $availableDays * * @return mixed */ public function removeDatesFromSimpleArray($availableDays) { $dates = $this->dates; if (is_array($dates)){ foreach($dates as $date) { $pos = array_search($date, $availableDays); if ($pos !== false && $pos >= 0){ unset($availableDays[$pos]); } } } return array_values($availableDays); } /** * Remove closed days from array * @param $availableDays * * @return mixed */ public function removeDatesAssociatedArray($availableDays) { $dates = $this->dates; if (is_array($dates)){ foreach($dates as $date) { unset($availableDays[$date]); } } return $availableDays; } /** * Ensure full_dates are always included in dates * Call this before saving to maintain data integrity * @return void */ public function syncFullDatesWithDates() { $dates = $this->dates ?? []; $fullDates = $this->full_dates ?? []; if (!is_array($dates)) { $dates = []; } if (!is_array($fullDates)) { $fullDates = []; } // Ensure all full_dates are in dates foreach ($fullDates as $fullDate) { if (!in_array($fullDate, $dates)) { $dates[] = $fullDate; } } $this->dates = $dates; } /** * Remove a date from full_dates if it's removed from dates * @param string $date * @return void */ public function removeDateFromFull($date) { $fullDates = $this->full_dates ?? []; if (is_array($fullDates)) { $pos = array_search($date, $fullDates); if ($pos !== false) { unset($fullDates[$pos]); $this->full_dates = array_values($fullDates); } } } }