conversation_id); if (!$conversation->hasParticipant(Auth::id())) { abort(403, 'You do not have access to this attachment.'); } // Get the attachment $attachments = $message->attachments; if (!$attachments || !isset($attachments[$attachmentIndex])) { abort(404, 'Attachment not found.'); } $attachment = $attachments[$attachmentIndex]; // Check if file exists if (!Storage::disk('local')->exists($attachment['path'])) { abort(404, 'Attachment file not found.'); } // Get file contents $file = Storage::disk('local')->get($attachment['path']); $mimeType = $attachment['type'] ?? 'application/octet-stream'; $fileName = $attachment['name'] ?? 'attachment'; // Return file response with appropriate headers return response($file, 200) ->header('Content-Type', $mimeType) ->header('Content-Disposition', 'inline; filename="' . $fileName . '"') ->header('Cache-Control', 'no-cache, no-store, must-revalidate') ->header('Pragma', 'no-cache') ->header('Expires', '0'); } }