*/ protected $fillable = [ 'ticket_id', 'parent_id', 'user_id', 'subject', 'body', 'body_text', 'is_internal', 'guid', 'unid', 'replica_id', 'parent_unid', 'root_unid', 'originator_id', 'sync_sequence', 'sync_hash', 'source_system', 'source_record_id', 'replicated_at', 'synced_at', 'tombstoned_at', 'deleted_by', 'delete_reason', ]; /** @var array */ protected $casts = [ 'is_internal' => 'boolean', 'sync_sequence' => 'integer', 'replicated_at' => 'datetime', 'synced_at' => 'datetime', 'tombstoned_at' => 'datetime', 'deleted_by' => 'integer', ]; /** @return BelongsTo */ public function ticket(): BelongsTo { return $this->belongsTo(Ticket::class, 'ticket_id'); } /** @return BelongsTo */ public function parent(): BelongsTo { return $this->belongsTo(self::class, 'parent_id'); } /** @return HasMany */ public function replies(): HasMany { return $this->hasMany(self::class, 'parent_id') ->active() ->oldest(); } /** @return BelongsTo */ public function deleter(): BelongsTo { return $this->belongsTo(User::class, 'deleted_by'); } /** @return BelongsTo */ public function user(): BelongsTo { return $this->belongsTo(User::class, 'user_id'); } /** @return HasMany */ public function attachments(): HasMany { return $this->hasMany(Attachment::class, 'comment_id'); } /** @param Builder $query */ public function scopeActive(Builder $query): Builder { return $query->whereNull('tombstoned_at'); } }