Laravel 6 - QR Code Generator Example

  • 10-04-2022
  • 1368
  • Laravel 6
  • Haresh Chauhan

Hello Artisan, In this tutorial, I would like to share with you how to generate QR Image in Laravel 6 Application. So, we install this package of simple-QRcode and make own QR code with an easy step. In this tutorial, I will guide you step by step how we can use that package and make own example. Here You can make a simple QR code image, specific URL, text, size, color, background, margin format, like png, etc.

You can generate QR image as per your need you can set also your birthdate, mobile number, address details with you can as well as many more information.

So let's do this task and generate a QR image and store some information.

Step 1 : Install Laravel Fresh Application

In this step we have to clone fresh Laravel 6 Application. If you have already exists Laravel Application then you can move on second step.

Otherwise using this command fire below command into your terminal or command prompt and get Laravel fresh Application and setup it.

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

Step 2 : Install simple-qrcode helper Package

Now, We need to simple-qrcode package for QR code generator. So, now let's run below command in your terminal.

composer require simplesoftwareio/simple-qrcode

After install the simple-qrcode package we have to change into our project config/app.php file.

Now we added below two lines into providers or aliases array. So, let's do that

config/app.php

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

How to create Excel file in Laravel 6

Step 3 : Create Route

After complete above configuration we will create one route to check Generate QR-image. So, let's make a one route.

routes/web.php

<?php
 Route::get('qr-image', function () {

  \QrCode::size(500)
    ->format('png')
    ->generate('webappfix.com', public_path('qr-image/qrimage.png'));

    return view('qr-image');
});

Step 4 : Create A Blade file.

Here, In this last step, we have to create one blade file for check QR-image generated or not. After the run route, we will show the Qr image into the blade file.

How to Generate PDF in Laravel 6

resources/views/qr-image.blade.php

<!DOCTYPE html>
<html>
 <head>
    <title> Laravel 6 QR code Generate example - webappfix.com </title>
 </head>
 <body>
  <div class="text-center">
   <h1> Laravel 6 QR code Generate example - webappfix.com </h1>
    {!! QrCode::size(500)->generate('webappfix.com'); !!}
   <p>example by webappfix.com.</p>

   <img src="{{ asset('qr-image/qrimage.png') }}">

  </div>
 </body>
</html>

We always thanks to you for reading our blogs.


dharmesh-image

Dharmesh Chauhan

(Swapinfoway Founder)

Hello Sir, We are brothers origin from Gujarat India, Fullstack developers working together since 2016. We have lots of skills in web development in different technologies here I mention PHP, Laravel, Javascript, Vuejs, Ajax, API, Payment Gateway Integration, Database, HTML5, CSS3, and Server Administration. So you need our service Please Contact Us

haresh-image

Haresh Chauhan

(Co-Founder)


We Are Also Recommending You :