Laravel qr code generator example tutorial

Hello buddies, How are you? I will show you how to generate QR code in laravel 8. In this article, we will implement a laravel qr code generator. 

Simple-qrcode is a composer package for generate QR code in your laravel 8 application.Simple laravel qr code generator provide to send sms and email with generated QR code. you can create QR code for geo, phoneNumber, birthdate using simple qrcode package.

Create Laravel project

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

Set Database Configuration properties

Go to the .env file and set you Database name, Database username and password.

 DB_CONNECTION=mysql
 DB_HOST=127.0.0.1
 DB_PORT=3306
 DB_DATABASE=laravelblog
 DB_USERNAME=root
 DB_PASSWORD=
Read Also: Google Recaptcha V3 Example Tutorial in Laravel 8

Install simple-qrcode Package

Now we require to install simple-qrcode package for generating QR code. Using laravel qr code generator package is the simplest way to generate QR code. So Open your terminal and run bellow command.

composer require simplesoftwareio/simple-qrcode
Official Doc: SimpleSoftwareIO / simple-qrcode by SimplyThomas
Github: SimpleSoftwareIO/simple-qrcode

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

config/app.php

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

Create Route

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

routes/web.php

Route::get('qr-generate', function () {
    
      QrCode::size(500)
              ->format('png')
              ->generate('This is Sample Product Name', public_path('images/qrcode.png'));
      
    return view('qrCode');
      
  });

Create Blade file

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

resources/views/qrCode.blade.php

<!DOCTYPE html>
<html>
<head>
    <title>How to Generate QR Code in Laravel 8.0</title>
</head>
<body>
    
<div>
    <h1>Laravel 8 - QR Code Generator Example</h1>
     
    {!! QrCode::size(250)->generate('This is Sample Product Name'); !!}
     
</div>
    
</body>
</html>

Hope it will helps!