qrCodes()->where('is_active', true)->update(['is_active' => false]); $token = Str::random(48); $url = route('public.checkin.show', $token); $path = 'public/qrcodes/' . $token . '.png'; $absPath = Storage::path($path); // Ensure directory exists Storage::makeDirectory('public/qrcodes'); // Generate QR code PNG (400×400, with quiet zone) $png = QrCode::format('png') ->size(400) ->margin(2) ->errorCorrection('H') ->generate($url); Storage::put($path, $png); return $program->qrCodes()->create([ 'token' => $token, 'qr_image_path' => $path, 'is_active' => true, ]); } public function getPublicUrl(ProgramQrCode $qrCode): string { return Storage::url($qrCode->qr_image_path); } public function getRawPng(ProgramQrCode $qrCode): string { return Storage::get($qrCode->qr_image_path); } }