*/ use HasFactory; /** * Get the attributes that should be cast. * * @return array */ /** * Defaults of the minimum stay rules (as in the migration), also before the model is reloaded. * * @var array */ protected $attributes = [ 'min_stay_fill_gaps' => true, 'min_stay_until_changeover' => false, 'min_stay_absolute' => 2, ]; protected function casts(): array { return [ 'is_active' => 'boolean', 'min_stay_fill_gaps' => 'boolean', 'min_stay_until_changeover' => 'boolean', 'changeover_weekday' => 'integer', 'min_stay_absolute' => 'integer', ]; } /** * @return HasMany */ public function seasons(): HasMany { return $this->hasMany(Season::class)->orderBy('starts_on'); } /** * @return HasMany */ public function bookings(): HasMany { return $this->hasMany(Booking::class); } /** * @return HasMany */ public function blockedPeriods(): HasMany { return $this->hasMany(BlockedPeriod::class)->orderBy('starts_on'); } /** * @return HasMany */ public function channels(): HasMany { return $this->hasMany(Channel::class); } /** * @return HasMany */ public function amenities(): HasMany { return $this->hasMany(Amenity::class)->orderBy('sort_order'); } /** * @return HasMany */ public function specialOffers(): HasMany { return $this->hasMany(SpecialOffer::class); } /** * Periods within [$from, $until) for which no season defines a price. * * @return list */ public function uncoveredPeriods(CarbonImmutable $from, CarbonImmutable $until): array { $gaps = []; $cursor = $from; foreach ($this->seasons()->overlapping($from, $until)->get() as $season) { if ($season->starts_on->greaterThan($cursor)) { $gaps[] = ['from' => $cursor, 'until' => $season->starts_on]; } $cursor = $cursor->max($season->ends_on); } if ($cursor->lessThan($until)) { $gaps[] = ['from' => $cursor, 'until' => $until]; } return $gaps; } /** * @return HasMany */ public function extras(): HasMany { return $this->hasMany(Extra::class)->orderBy('sort_order'); } }