*/ use HasFactory; /** * Get the attributes that should be cast. * * @return array */ protected function casts(): array { return [ 'starts_on' => 'immutable_date', 'ends_on' => 'immutable_date', ]; } /** * @return BelongsTo */ public function property(): BelongsTo { return $this->belongsTo(Property::class); } /** * Seasons that share at least one night with the half-open period [$from, $until). * * @param Builder $query * @return Builder */ #[Scope] protected function overlapping(Builder $query, CarbonInterface $from, CarbonInterface $until): Builder { return $query ->whereDate('starts_on', '<', $until) ->whereDate('ends_on', '>', $from); } public function containsNight(CarbonInterface $night): bool { return $this->starts_on->lessThanOrEqualTo($night) && $this->ends_on->greaterThan($night); } }