published_at !== null && $this->published_at->isFuture(); } /** * Past its end date, and therefore off the site. */ public function hasExpired(): bool { return $this->unpublish_at !== null && $this->unpublish_at->isPast(); } /** * About to go, so it can be flagged before somebody notices it vanished. */ public function expiresSoon(int $days = 7): bool { return $this->unpublish_at !== null && $this->unpublish_at->isFuture() && $this->unpublish_at->lt(now()->addDays($days)); } /** * @param Builder $query * @return Builder */ public function scopeScheduled(Builder $query): Builder { return $query->whereNotNull('published_at')->where('published_at', '>', now()); } /** * @param Builder $query * @return Builder */ public function scopeExpired(Builder $query): Builder { return $query->whereNotNull('unpublish_at')->where('unpublish_at', '<=', now()); } }