Laravel 7 Qr Code Generator Example




Whenever you are working on a web application in Laravel, then you need to create the QR codes after doing it. For example, if you want to make QR code from the text or number, or make QR code from the image, or make color  QR code.

In this tutorial you will learn how to generate or create qr codes in your laravel web applications. This tutorial show you simple way to generate or create different types of QR codes in laravel web applications.

Laravel Generate QR Code Example

  • Install Laravel Application
  • Configure Database Detail
  • Install QR Code Package
  • Create Routes
  • Generate Controller By Artisan
  • Create Blade View
  • Start Development Server

Install Laravel Application

First Step, you need to download or install laravel web application new setup on your local machine. you can use the following command to download or install laravel application new setup:

composer create-project laravel/laravel laravel-qr-code –-prefer-dist

If you want to install a specific version of laravel, you can follow the following tutorial

Configure Database Detail

After that, you will set up the database credentials in .env file. So open your .env file and update database credentials following:


Install QR Code Package

Next, you need to Install QR Code Package laravel package in your web applications. So go to your command prompt and run the following command to install the latest laravel QR Code Package:

composer require simplesoftwareio/simple-qrcode

When the package of QR Code is installed. After that this package will have to be registered in the Laravel web application of the app. For this, you can register this package of instruction follow below.


'providers' => [



'aliases' => [
  'QrCode' => SimpleSoftwareIO\QrCode\Facades\QrCode::class


Create Routes

Next step, go to routes/web.php file and update the following routes into your file:

//display users list
Route::get('simple-qr-code','[email protected]');
Route::get('color-qr-code','[email protected]');
Route::get('image-qr-code','[email protected]');

Generate Controller By Artisan

Now, you need to generate or create a controller file using php artisan command, so use the php artisan make:controller command and generate/create a new controller file:

php artisan make:controller GenerateQrCodeController

We will create some methods in this controller file. This method will generate or create simple QR code, color QR code, and image QR code.

After that, go to App/Http/Controllers/ directory and find the created GenerateQrCodeController  file and update the following code into your file:

namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Validator,Redirect,Response;
class GenerateQrCodeController extends Controller
    public function simpleQrCode() 

      \QrCode::size(300)->generate('A basic example of QR code!');

    public function colorQrCode() 

     return \QrCode::size(300)
             ->generate('A simple example of QR code');
    public function imageQrCode() 

      $image = \QrCode::format('png')
               ->merge('images/laravel.png', 0.5, true)
               ->generate('A simple example of QR code!');
      return response($image)->header('Content-type','image/png');


Start development server

You can use the following command artisan command to start the development server:

php artisan serve

The final step, go to your browser and type the below-given URL into your browser:





This tutorial idea has taken from the following urls: