*/ #[\Override] protected $casts = [ 'starts_at' => 'datetime', 'ends_at' => 'datetime', 'is_active' => 'boolean', 'is_ended' => 'boolean', 'winner_announced' => 'boolean', 'prize_value' => 'decimal:2', ]; public function winner(): BelongsTo { return $this->belongsTo(User::class, 'winner_id'); } public function participants(): HasMany { return $this->hasMany(RadioGiveawayParticipant::class); } public function isActive(): bool { return $this->is_active && now()->gte($this->starts_at) && now()->lte($this->ends_at) && ! $this->is_ended; } public function hasEnded(): bool { return now()->isAfter($this->ends_at) || $this->is_ended; } public function announceWinner(User $user): void { $this->update([ 'winner_id' => $user->id, 'winner_announced' => true, 'is_ended' => true, ]); } public function participantCount(): int { return $this->participants()->count(); } }