find($reportId); if (! $row || empty($row->attachment_path)) { abort(404, 'Attachment not found.'); } $file = $this->resolveAttachmentFile($row->toArray()); if (! $file) { abort(404, 'Attachment missing.'); } return response()->download($file, basename($file)); } /** * Download file from normalized attachments table */ public function downloadAttachment(int $attachmentId): BinaryFileResponse { $attachment = ClassProgressAttachment::query()->find($attachmentId); if (! $attachment || empty($attachment->file_path)) { abort(404, 'Attachment not found.'); } $file = $this->resolveAttachmentPath((string) $attachment->file_path); if (! $file) { abort(404, 'Attachment missing.'); } $downloadName = $attachment->original_name ?: basename($file); return response()->download($file, $downloadName); } }