*/ use HasFactory; public const string TypeText = 'text'; public const string TypeFile = 'file'; /** * @return array */ protected function casts(): array { return [ 'metadata' => 'array', 'edited_at' => 'datetime', ]; } /** * @return BelongsTo */ public function conversation(): BelongsTo { return $this->belongsTo(Conversation::class); } /** * @return BelongsTo */ public function sender(): BelongsTo { return $this->belongsTo(User::class, 'user_id'); } /** * @return BelongsTo */ public function user(): BelongsTo { return $this->belongsTo(User::class); } public function isFile(): bool { return $this->type === self::TypeFile; } public function attachmentDisk(): string { return (string) data_get($this->metadata, 'disk', 'local'); } public function attachmentPath(): ?string { $path = data_get($this->metadata, 'path'); return is_string($path) && $path !== '' ? $path : null; } public function attachmentName(): string { $name = data_get($this->metadata, 'original_name'); if (is_string($name) && $name !== '') { return $name; } return $this->body ?: __('Attachment'); } public function attachmentMimeType(): ?string { $mimeType = data_get($this->metadata, 'mime_type'); return is_string($mimeType) && $mimeType !== '' ? $mimeType : null; } public function attachmentSize(): int { return (int) data_get($this->metadata, 'size', 0); } public function formattedAttachmentSize(): string { $size = $this->attachmentSize(); return $size > 0 ? Number::fileSize($size) : __('Unknown size'); } }