Laravel with Packages | Laravel 8 QR Code Generate Example

Raviya Technical
2 min readJun 6, 2022

In this example, I will show you how to generate QR codes in laravel 8. In this article, we will implement a laravel 8 QR code example. In this article, we will implement a how-to create QR code in laravel 8. if you want to see an example of how to make a QR code in laravel 8 then you are in a right place.

simple-QRcode is a composer package for generating QR codes in your laravel 8 application. simple-QRcode provides to send SMS and email with generated QR code. you can create QR codes for geo, phone number, and birthdate using a simple QR code package.

after generating the QR code, we might be required to write code for the scan code using jquery. if you same requirement for scan QR codes using jquery then you can follow this tutorial: QR code scanner using instance js.

Here, I write examples step by step to generate QR codes in your laravel 5 admin panel. so let’s follow a few steps to get this example:

Preview:

Step 1: Install Laravel 8

In the first step, If you haven’t installed laravel 8 in your system then you can run the below command and get a fresh Laravel project.

composer create-project --prefer-dist laravel/laravel blog

Step 2: Install simple-QRcode Package

Now we require to install a simple-QRcode package for the QR code generator, that way we can use its method. So open your terminal and run the below command.

composer require simplesoftwareio/simple-qrcode

Now open the config/app.php file and add the service provider and alias.

config/app.php

'providers' => [....SimpleSoftwareIO\QrCode\QrCodeServiceProvider::class],'aliases' => [....'QrCode' => SimpleSoftwareIO\QrCode\Facades\QrCode::class],

Step 3: Create Route

In this step, we will create one route for testing for example. So, let’s add a new route to that file.

routes/web.php

<?phpRoute::get('qr-code-g', function () {

\QrCode::size(500)
->format('png')
->generate('raviyatechnical', public_path('images/qrcode.png'));

return view('qrCode');

});

Step 4: Create a Blade file

now we need to create qrCode.blade.php to display the QR code. so let’s create a blade file as like bellow code:

resources/views/qrCode.blade.php

<!DOCTYPE html><html><head><title>How to Generate QR Code in Laravel 8? - raviyatechnical</title></head><body><div class="visible-print text-center"><h1>Laravel 8 - QR Code Generator Example</h1>{!! QrCode::size(250)->generate('raviyatechnical'); !!}<p>example by raviyatechnical.</p></div></body></html>

Now you can run and check it.

I hope it can help you…

--

--