Level 75
Any log errors? What does the network tab show?
1 like
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Controller:
public function preview($id)
{
$attachment = HR_Attachments::findOrFail($id);
$file_path = $attachment->file_path;
if (!Storage::disk('protected')->exists($file_path)) {
abort(404, 'File not found.');
}
$absolutePath = Storage::disk('protected')->path($file_path);
$mimeType = Storage::disk('protected')->mimeType($file_path);
return response()->file($absolutePath, [
'Content-Type' => $mimeType,
'Cache-Control' => 'private, no-store, no-cache',
]);
}
Route:
Route::get('/attachments/{id}/preview', [AttachmentController::class, 'preview'])->name('attachments.preview');
Blade:
@if (in_array(strtolower($attachment->file_type), ['png', 'jpg', 'jpeg']))
<img
src="{{ route('attachments.preview', $attachment->id) }}"
alt="{{ $attachment->title ?? 'Attachment' }}"
class="w-full rounded-xl border object-cover"
/>
@else
<iframe
src="{{ route('attachments.preview', $attachment->id) }}#toolbar=0"
class="w-full h-[600px] border"
></iframe>
@endif
Please or to participate in this conversation.