<?php
 namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Facades\Storage; class Attachment extends Model { use HasFactory; protected $fillable = [ 'original_name', 'file_name', 'file_path', 'mime_type', 'file_size', 'uploadable_type', 'uploadable_id', 'upload_source', 'uploaded_by', 'scan_status', 'scan_message', ]; public function scanPassed(): bool { return $this->scan_status === null || $this->scan_status === 'clean'; } public function isQuarantined(): bool { return $this->scan_status === 'infected'; } public function thumbnailPath(): string { return 'thumbnails/'.$this->id.'.jpg'; } public function hasThumbnail(): bool { return Storage::disk('public')->exists($this->thumbnailPath()); } public function uploadable() { return $this->morphTo(); } public function getFormattedSizeAttribute() { $bytes = $this->file_size; $units = ['B', 'KB', 'MB', 'GB', 'TB']; for ($i = 0; $bytes > 1024 && $i < count($units) - 1; $i++) { $bytes /= 1024; } return round($bytes, 2).' '.$units[$i]; } public function fileExists() { return Storage::disk('attachments')->exists($this->file_path) || Storage::disk('public')->exists($this->file_path); } public function getSecureDownloadUrl($ticketId = null) { if ($ticketId) { return route('store.auth.tickets.attachment.download', [$ticketId, $this->id]); } return null; } public function getUrlAttribute() { return route('admin.file-download', $this->id); } } 