From 5deccec8ba1b727f695e3887763eb2da8b2bff92 Mon Sep 17 00:00:00 2001 From: husanjon Date: Thu, 23 Apr 2026 12:08:47 +0500 Subject: [PATCH] addres qoshish da api o'zgartirildi --- app/Http/Controllers/QrController.php | 32 +++++++++++++++++++++------ 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/app/Http/Controllers/QrController.php b/app/Http/Controllers/QrController.php index 561663f..f6a9b34 100644 --- a/app/Http/Controllers/QrController.php +++ b/app/Http/Controllers/QrController.php @@ -53,13 +53,27 @@ class QrController extends Controller public static function generateQr($id, $type) { - // type is 'auto_' or 'estate_' - $cleanType = str_replace('_', '', $type); - $url = route('qr.verify', ['type' => $cleanType, 'id' => $id]); - $dir = 'public/attachments/' . $type . $id; - Storage::makeDirectory($dir); - $qr = QrCode::format('png')->size(200)->generate($url); - Storage::put($dir . '/qr.png', $qr); + try { + $cleanType = str_replace('_', '', $type); + $url = route('qr.verify', ['type' => $cleanType, 'id' => $id]); + $dir = 'public/attachments/' . $type . $id; + $absDir = storage_path('app/' . $dir); + + if (!is_dir($absDir)) { + mkdir($absDir, 0755, true); + } else { + chmod($absDir, 0755); + } + + $qr = QrCode::format('png')->size(200)->generate($url); + $qrPath = $absDir . '/qr.png'; + file_put_contents($qrPath, $qr); + chmod($qrPath, 0644); + } catch (\Exception $e) { + \Illuminate\Support\Facades\Log::error('QR generate failed: ' . $e->getMessage(), [ + 'id' => $id, 'type' => $type, + ]); + } } public function qrImage($type, $id) @@ -67,6 +81,10 @@ class QrController extends Controller $dbType = $type === 'auto' ? 'auto_' : 'estate_'; $path = storage_path('app/public/attachments/' . $dbType . $id . '/qr.png'); + if (!file_exists($path)) { + self::generateQr($id, $dbType); + } + if (!file_exists($path)) { abort(404); }