'boolean', 'published_at' => 'datetime', ]; /** * Get the images for the news article. */ public function images(): HasMany { return $this->hasMany(NewsImage::class)->orderBy('order'); } /** * Get the user who created the news article. */ public function user(): BelongsTo { return $this->belongsTo(User::class); } /** * Check if the news article is published. */ public function isPublished(): bool { return $this->active && ($this->published_at === null || $this->published_at->isPast()); } /** * Scope to get only published news. */ public function scopePublished($query) { return $query->where('active', true) ->where(function ($q) { $q->whereNull('published_at') ->orWhere('published_at', '<=', now()); }); } }