'integer', ]; public function letter() { return $this->belongsTo(Letter::class); } /** * Get the URL for the attachment. */ public function getUrlAttribute(): string { return Storage::disk('public')->url($this->file_path); } /** * Check if the attachment is an image. */ public function getIsImageAttribute(): bool { return str_starts_with($this->mime_type ?? '', 'image/'); } /** * Check if the attachment is a PDF. */ public function getIsPdfAttribute(): bool { return ($this->mime_type ?? '') === 'application/pdf'; } /** * Get the formatted file size. */ public function getFormattedSizeAttribute(): string { $bytes = $this->file_size ?? 0; if ($bytes >= 1048576) { return round($bytes / 1048576, 1) . ' MB'; } if ($bytes >= 1024) { return round($bytes / 1024, 1) . ' KB'; } return $bytes . ' B'; } protected static function booted() { static::creating(function ($attachment) { if (empty($attachment->created_at)) { $attachment->created_at = now(); } }); } }