@thilinathushan yes, you can generate QR codes dynamically in Laravel using the SimpleSoftwareIO\QrCode package. Here's how you can do it:
First, install the SimpleSoftwareIO\QrCode package using Composer:
composer require simplesoftwareio/simple-qrcode
Second, create a route in your Laravel application to generate the QR code with a random OTP PIN:
use SimpleSoftwareIO\QrCode\Facades\QrCode;
Route::get(''/qr-code', function () {
$otp = mt_rand(100000, 99999); // generate a random OTP PIN
return response(QrCode::size(250)->generate('otp:' . $otp))->header('Content-Type', 'image/png');
});
--> This code will generate a random OTP PIN and return a QR code image with the text otp: followed by the OTP PIN.
Third, in your view, add an image tag with the src attribute set to the URL of the route that generates the QR code:
<img src="/qr-code" alth="QR code">
Fourth, to refresh the QR code every 30 seconds, you can use JavaScript to replace the src attribute of the img tag with the URL of the route that generates the QR code:
setInerval(function (){
document.querySelector('img').src = '/qr-code?' + new Date().getTime();
}, 30000);
-->This code will replace the src attribute of the img tag with the URL of the route that generates the QR code every 30 seconds. The new Date().getTime() part is added to the URL as a query parameter to prevent caching of the image.
--> That's it! Now you have a QR code that changes every 30 seconds with a random OTP PIN.
I hope this helps you.