Laravel URL QR Code Generator

|
| By Webner

Why the QR Code?

A QR code can make you download apps, redirect to a particular URL, access wireless networks like WiFi and much more. They can also lead one to perform quick actions without even putting any effort. Many social media platforms are using the same as it has great user awareness.

How to generate a QR Code?

Here, in the following example, one can generate a QR for a particular URL. Follow these steps to achieve the same:

  1. Install simple-qrcode Package
    We need to install a simple-qrcode package to generate QR in our project. Go to the terminal, and run the following command inside the Laravel project:

composer require simplesoftwareio/simple-qrcode

After the package is installed successfully, we will address the package inside the Laravel framework service providers and also give aliasing to the same by editing config/app.php, so that it would be available globally inside the Laravel Project.
Add the below lines inside config/app.php
'providers' => [
....
SimpleSoftwareIO\QrCode\QrCodeServiceProvider::class
] 'aliases' => [
....
'QrCode' => SimpleSoftwareIO\QrCode\Facades\QrCode::class
]

  • Create Route: We will be creating the Route file to access the package and return it to the respected View.
    <?php
    Route::get('getQR', function () {
    \QrCode::size(500)
    ->format('png')
    ->generate(webnersolutions.com', public_path('qrcode.png'));
    return view('qrCode');
    });
  • Create Blade File: Create a file qrCode.blade.php to display the generated QR Code.
    <html>
    <head>
    <title></title>
    </head>
    <body>
    <div class="d-print-block text-center">
    <h1>QR Code Generator</h1>
    {!! QrCode::size(250)->generate('webnersolutions.com'); !!}
    </div>
    </body>
    </html>

 

Here is the generated Code :
qr code

What is the use of QR code?

QR codes can make you download apps, redirect to a particular URL, access wireless networks like WiFi and much more. QR Codes can also lead one to perform quick actions without even putting any effort.

Where are QR codes used?

QR codes are used on social media for quick links. Many payment platforms have also recently started using them.

How can we make the QR package globally available in the project?

We can address the package inside the Laravel framework service providers and also give aliasing to the same by editing config/app.php, so that it would be available globally inside the Laravel Project.

Leave a Reply

Your email address will not be published. Required fields are marked *