Laravel 8 QR Code Generator Example

Websolutionstuff | Jan-24-2022 | Categories : Laravel PHP

In this tutorial, we will see the laravel 8 QR code generator example. we will generate QR code using simplesoftwareio/simple-qrcode package in laravel 8. simplesoftwareio/simple-qrcode package is an easy-to-use PHP QR Code generator with first-party support for laravel 8.

Using this simplesoftwareio/simple-qrcode package, you can generate a simple QR code, text QR code, image QR code in laravel 8. Also, you can customize as per requirements like color, size, text, height, width, etc.

You can read more on SimpleSoftwareIO simple-qrcode and also read Official Documentation.

So, let's see how to generate QR code in laravel 8 using simplesoftwareio/simple-qrcode.

Step 1 : Create Laravel 8 Project

Step 2 : Configure Database

Step 3 : Install QR Code Package

Step 4 : Create Controller

Step 5 : Add Route

Step 6 : Generate QR Codes in Blade View

Step 7 : Run Laravel App

 

Step 1 : Create Laravel 8 Project

In this step, we will create laravel 8 project using the below command.

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

 

 

Step 2 : Configure Database

Now, we will set up database configuration in the .env file.

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=database_name
DB_USERNAME=database_user_name
DB_PASSWORD=database_password

 

Step 3 : Install QR Code Package

In the third step, we will install simplesoftwareio/simple-qrcode package using the below command.

composer require simplesoftwareio/simple-qrcode

 

 

Step 4 : Create Controller

After installing the package, create a QRCodeController using the below command.

php artisan make:controller QRCodeController

In QRCodeController add the below code.

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use QrCode;

class QRCodeController extends Controller
{
    public function index()
    {
      return view('qr_code');
    }
}

 

Step 5 : Add Route

Now, we will add the qr-code route in the web.php file.

use App\Http\Controllers\QRCodeController;
Route::get('/qr-code', [QRCodeController::class, 'index'])->name('qr-code');

 

 

Step 6 : Generate QR Codes in Blade View

In this step, create a qr_code blade file and add the below code in that file.

<!DOCTYPE html>
<html>
<head>
  <title>Laravel 8 QR Code Generator Example - Websolutionstuff</title>
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
</head>
<body>
    <div class="container">
        <div class="row text-center mt-5">
            <div class="col-md-6">
                <h4>Simple QR Code</h4>
                {!! QrCode::size(150)->generate('websolutionstuff.com') !!}
            </div>
            <div class="col-md-6">
                <h4>Color Qr Code</h4>
                {!! QrCode::size(150)->backgroundColor(255,55,0)->generate('websolutionstuff.com') !!}
            </div>
        </div> 
    </div> 
</body>
</html>

 

Step 7 : Run Laravel App

Now, run laravel project using the below command.

php artisan serve

 

 

Now, open the below URL on your browser.

http://localhost:8000/qr-code

 


You might also like :

Recommended Post
Featured Post
MilesWeb Review: Why Go for Its Shared Hosting?
MilesWeb Review: Why Go for It...

For finding the right web hosting provider, you need to do a lot of research. There are hundreds of web hosting provider...

Read More

Nov-12-2021

Advanced Custom Error Handling and Logging Strategies in Laravel 11
Advanced Custom Error Handling...

Hello, laravel web developers! In this guide, I’ll walk you through setting up advanced error handling and logging...

Read More

Oct-04-2024

How To Get env Variable In Controller Or Blade File
How To Get env Variable In Con...

In this tutorial, I will give you information on how to get the .env variable in the controller or file. Many times we n...

Read More

Jul-26-2020

Require ext-curl is missing from your system ubuntu
Require ext-curl is missing fr...

In this article, we will see require ext-curl * is missing from your system in ubuntu. When we set up the laravel 9...

Read More

Feb-16-2023