*/ use HasFactory; /** * Get the attributes that should be cast. * * @return array */ protected function casts(): array { return [ 'is_active' => 'boolean', ]; } /** * @return HasMany */ public function seasons(): HasMany { return $this->hasMany(Season::class)->orderBy('starts_on'); } /** * 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'); } }