Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

mawime's avatar
Level 1

AFter i save , i cant rerender the html5-qrcode scanner

function initializeScanner() { htmlscanner = new Html5QrcodeScanner( "my-qr-reader", { fps: 10, qrbox: 250, rememberLastUsedCamera: true, showTorchButtonIfSupported: true, showZoomSliderIfSupported: true, verbose: false, disableFlip: true, aspectRatio: 1.0 }, );

        htmlscanner.render(onScanSuccess);
    }
            

    @this.on('qrscanner', function () {
        initializeScanner()
    });
    initializeScanner();

    function onScanSuccess(decodeText, decodeResult) {
        barcodeInput.value = decodeText;
        var activeTab = document.querySelector('.nav-link.active').id;
        var type = activeTab.split('-')[0];


        // Stop the scanner
         Swal.fire({
                title: 'Processing...',
                text: 'Please wait...',
                timer: 2000,
                timerProgressBar: true,
                didOpen: () => {
                    htmlscanner.pause();
                },
                willClose: () => {
                    Livewire.dispatch('addMealService', { data: decodeText, type: type });
                    barcodeInput.value = ''; // Clear the input after processing
                    }
                }).then((result) => {
                    htmlscanner.resume();
                });

                
    }

public function addMealService($data,$type) { \Log::info('Data received in Livewire component', ['user_id' => $type]);

    $user = users_tbl::where('pgh_id', $data)->first();

    if ($user) {
        $today = Carbon::now('Asia/Manila')->startOfDay();
        $existingEntry = meal_service::where('user_id', $user->user_id)
            ->where('scan_date', '>=', $today)
            ->exists();

        if ($existingEntry) {
            $this->dispatch('error', 'Meal service entry already exists for today.');
        } else {
            meal_service::create([
                'user_id' => $user->user_id,
                'scan_date' => Carbon::now('Asia/Manila'),
                'type' => $type,
            ]);

            $this->dispatch('qrscanner');
        }
    } else {
        $this->dispatch('error', 'User not found.');
    }
}
0 likes
0 replies

Please or to participate in this conversation.