From 7ca4eec96585e076bb1e8d0047e6fe534ce2adf4 Mon Sep 17 00:00:00 2001 From: dhanabalan Date: Tue, 1 Dec 2026 15:34:11 +0530 Subject: [PATCH] Added pdf shown logic in request characteristics route --- routes/web.php | 39 ++++++++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/routes/web.php b/routes/web.php index f31f55d0..92a23bb5 100644 --- a/routes/web.php +++ b/routes/web.php @@ -141,14 +141,43 @@ Route::get('/part-validation-image/{filename}', function ($filename) { return response()->file($path); })->name('part.validation.image'); -Route::get('/workflow-image/{filename}', function ($filename) { - $path = storage_path("app/private/uploads/LaserDocs/{$filename}"); +// Route::get('/workflow-image/{filename}', function ($filename) { +// $path = storage_path("app/private/uploads/LaserDocs/{$filename}"); - if (! file_exists($path)) { - abort(404, 'Image not found'); +// if (! file_exists($path)) { +// abort(404, 'Image not found'); +// } + +// return response()->file($path); +// })->name('workflow.image'); + +Route::get('/workflow-image/{filename}', function ($filename) { + + $directory = storage_path('app/private/uploads/LaserDocs'); + + $files = glob($directory . '/' . basename($filename)); + + if (empty($files)) { + abort(404, 'File not found'); } - return response()->file($path); + $path = $files[0]; + + $extension = strtolower(pathinfo($path, PATHINFO_EXTENSION)); + + if ($extension === 'pdf') { + return response()->file($path, [ + 'Content-Type' => 'application/pdf', + 'Content-Disposition' => 'inline; filename="' . basename($path) . '"', + ]); + } + + if (in_array($extension, ['png', 'jpg', 'jpeg'])) { + return response()->file($path); + } + + abort(403, 'Unsupported file format'); + })->name('workflow.image'); // web.php