belongsTo(Issue::class); } public function user(): BelongsTo { return $this->belongsTo(User::class); } public function getFileSizeHumanAttribute(): string { $bytes = $this->file_size; $units = ['B', 'KB', 'MB', 'GB']; for ($i = 0; $bytes > 1024 && $i < count($units) - 1; $i++) { $bytes /= 1024; } return round($bytes, 2) . ' ' . $units[$i]; } public function getDownloadUrlAttribute(): string { return route('admin.issues.attachments.download', $this); } protected static function boot() { parent::boot(); static::deleting(function ($attachment) { // Delete file from storage when attachment record is deleted if (Storage::exists($attachment->file_path)) { Storage::delete($attachment->file_path); } }); } }