*/ use BelongsToTenant, HasFactory; /** * Get the attributes that should be cast. * * @return array */ protected function casts(): array { return [ 'action' => ChannelTaskAction::class, 'status' => ChannelTaskStatus::class, 'starts_on' => 'immutable_date', 'ends_on' => 'immutable_date', 'completed_at' => 'immutable_datetime', 'reminded_at' => 'immutable_datetime', 'automation_sent_at' => 'immutable_datetime', ]; } /** * @return BelongsTo */ public function channel(): BelongsTo { return $this->belongsTo(Channel::class); } /** * @param Builder $query * @return Builder */ #[Scope] protected function open(Builder $query): Builder { return $query->where('status', ChannelTaskStatus::Open); } public function complete(string $completedBy): void { $this->update([ 'status' => ChannelTaskStatus::Done, 'completed_by' => $completedBy, 'completed_at' => now(), ]); } /** * Human readable period, e.g. "14.06.2027 – 21.06.2027". */ public function period(): string { return $this->starts_on->format('d.m.Y').' – '.$this->ends_on->format('d.m.Y'); } }