'datetime', ]; // ── Relationships ──────────────────────────────────────────────────────── public function conversation(): BelongsTo { return $this->belongsTo(Conversation::class); } public function sender(): BelongsTo { return $this->belongsTo(User::class, 'sender_id'); } public function reactions(): HasMany { return $this->hasMany(MessageReaction::class); } public function attachments(): HasMany { return $this->hasMany(MessageAttachment::class); } public function setBodyAttribute(string $value): void { $sanitized = trim(strip_tags($value)); $this->attributes['body'] = $sanitized; } public function searchableAs(): string { return config('messaging.search.index', 'messages'); } public function shouldBeSearchable(): bool { return $this->deleted_at === null; } public function toSearchableArray(): array { return [ 'id' => (int) $this->id, 'conversation_id' => (int) $this->conversation_id, 'sender_id' => (int) $this->sender_id, 'sender_username' => (string) ($this->sender?->username ?? ''), 'body_text' => trim(strip_tags((string) $this->body)), 'created_at' => optional($this->created_at)->timestamp ?? now()->timestamp, 'has_attachments' => $this->relationLoaded('attachments') ? $this->attachments->isNotEmpty() : $this->attachments()->exists(), ]; } }