Skip to content
Readerstacks logo Readerstacks
  • Home
  • Softwares
  • Angular
  • Php
  • Laravel
  • Flutter
Readerstacks logo
Readerstacks
Laravel 8 generate qr code

How to generate qr code in Laravel 8?

Aman Jain, October 16, 2021November 16, 2021

In this article we will learn to generate the qr code in Laravel. we will use a simple example to generate the qr code. As we know qr code is stand for Quick Response and we can scan and get the information from it. we can use qr code in multiple way like to share the coupon, GPS, payment etc.

In this tutorial we will user simple-qrcode package of Laravel 8 application to generate the qr code. This package is capable of generating phone number, email, geo, colored qr code, image etc.

Before start i assume you know how to install and setup Laravel if not then you can read this guide How to install laravel 8 ?.

Let’s begin the tutorial Qr Code Generate in Laravel Online with simple steps

Step 1: Install simple-qrcode Package

After installation of Laravel 8, our first step is to install the simple-qrcode package, so open the terminal in project and type below command

composer require simplesoftwareio/simple-qrcode

This will add simple-qrcode package to our project.

Step 2: Add package in service provider

Now, we have installed the package but not registered in our service provider. open file config/app.php

'providers' => [
    ....
   SimpleSoftwareIO\QrCode\QrCodeServiceProvider::class

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

Here, we added QrCodeServiceProvider and aliases to access the QrCode package in our application with simple name.

Step 4: Create Route

we have installed and defined the package in our app.php. now, it’s time to execute and run it. so, create the route in web.php

<?php
use Illuminate\Support\Facades\Route;
use \App\Http\Controllers\QRController;


Route::get('/view-qr-code',[QRController::class, 'view']);

Step 5: Create Controller

Now, generate the controller for route

php artisan make:controller QrCodeController
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class QRController extends Controller
{
    public function view() 
    {
      $qrCodeSimple = \QrCode::size(300)->generate('ReaderStacks');
       return view('qr-code',['qrCodeSimple'=>$qrCodeSimple]);
    }
}

Step 6: Create view blade file

Now, create a view file to show the qr code

<!DOCTYPE html>
<html >
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">

        <title>Laravel 8 qr code generator</title>
 <link href="//netdna.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet" />
 <style>
     .jsc{
         justify-content: center;
     }
 </style>
   </head>
    <body class="antialiased">
    <div class="container">
    
    <div class="readersack">
      <div class="container">
        <div class="row">
          
        </div>
        <div class="row jsc">
          <!-- show qr code here -->
            {!! $qrCodeSimple!!}

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

Now, open the browser and output will be

Screenshot 2021 10 16 at 11.16.46 AM
Laravel qr code generator

Generating Laravel qr code with color

We can change the of qr code by simply adding few lines of code to it

$qrCodeSimple = \QrCode::size(300)->backgroundColor(255,55,0)->generate('ReaderStacks');

//QrCode::color(255, 0, 0); // Red QrCode
//QrCode::color(255, 0, 0, 25); //Red QrCode with 25% transparency 
Screenshot 2021 10 16 at 11.23.45 AM
Laravel colorful qr code generator

Generating Qr code with Text

QrCode::SMS('97728177671', 'Your message is here');

Generating Qr code with Phone Number

QrCode::phoneNumber('97728177671');

Generating Qr code with Email

QrCode::size(300)->email('admin@readerstacks.com', 'Welcome to readerstacks.');

Generating Qr code in a png image and save to storage

QrCode::size(300)->->format('png')
            ->generate('readerstacks.com', public_path('images/qrcode.png'));

Generating Qr code with URL

QrCode::size(300)->generate('https://readerstacks.com');

You can check complete list

UsagePrefixExample
Website URLhttp://http://www.simplesoftware.io
Secured URLhttps://https://www.simplesoftware.io
E-mail Addressmailto:support@simplesoftware.io
Phone Numbertel:tel:555-555-5555
Text (SMS)sms:sms:555-555-5555
Text (SMS) With Pretyped Messagesms:sms::I am a pretyped message
Text (SMS) With Pretyped Message and Numbersms:sms:555-555-5555:I am a pretyped message
Geo Addressgeo:geo:-78.400364,-85.916993
MeCardmecard:MECARD:Simple, Software;Some Address, Somewhere, 20430;TEL:555-555-5555;EMAIL:support@simplesoftware.io;
VCardBEGIN:VCARDSee Examples
Wifiwifi:wifi:WEP/WPA;SSID;PSK;Hidden(True/False)

Source https://www.simplesoftware.io/#/docs/simple-qrcode

Related

Php Laravel

Post navigation

Previous post
Next post

Related Posts

Php How to Permanent Delete Soft Deleted Records in Laravel 9

How to Permanent Delete Soft Deleted Records in Laravel 9 ?

June 18, 2022June 18, 2022

In this article we will learn to Permanent Delete soft deleted records in Laravel. In our recent article How to fetch Soft Deleted Records in Laravel 9 ? and How to Restore Soft Deleted Records in Laravel 9 we learnt to fetch the records from database and Restore the records…

Read More
Laravel 3 Ways to Remove public from URL in Laravel

3 Ways to Remove public from URL in Laravel

August 22, 2021November 8, 2023

Laravel comes with default server for local environment and but if run the application in apache then we need to remove the public from URL because if we serve the application through the Apache then we need to call the URLs from public directory. It can be multiple way to…

Read More
Php A Complete guide to Laravel 8 response

A Complete guide to Laravel 8 response

December 1, 2021November 5, 2023

In this tutorial we will learn about the Laravel response. Laravel has its own library to handle the http response of the application to browser. In the most of the cases response() method is used to send the response back to browser and class Illuminate\Http\Response is also used for same…

Read More

Aman Jain
Aman Jain

With years of hands-on experience in the realm of web and mobile development, they have honed their skills in various technologies, including Laravel, PHP CodeIgniter, mobile app development, web app development, Flutter, React, JavaScript, Angular, Devops and so much more. Their proficiency extends to building robust REST APIs, AWS Code scaling, and optimization, ensuring that your applications run seamlessly on the cloud.

Categories

  • Angular
  • CSS
  • Dart
  • Devops
  • Flutter
  • HTML
  • Javascript
  • jQuery
  • Laravel
  • Laravel 10
  • Laravel 11
  • Laravel 9
  • Mysql
  • Php
  • Softwares
  • Ubuntu
  • Uncategorized

Archives

  • August 2025
  • July 2025
  • June 2025
  • May 2025
  • April 2025
  • October 2024
  • July 2024
  • February 2024
  • January 2024
  • December 2023
  • November 2023
  • October 2023
  • July 2023
  • March 2023
  • November 2022
  • October 2022
  • September 2022
  • August 2022
  • July 2022
  • June 2022
  • May 2022
  • April 2022
  • March 2022
  • February 2022
  • January 2022
  • December 2021
  • November 2021
  • October 2021
  • September 2021
  • August 2021
  • July 2021
  • June 2021

Recent Posts

  • The Transformative Power of Education in the Digital Age
  • Understanding High Vulnerabilities: A Closer Look at the Week of July 14, 2025
  • Exploring Fresh Resources for Web Designers and Developers
  • The Intersection of Security and Technology: Understanding Vulnerabilities
  • Mapping Together: The Vibrant Spirit of OpenStreetMap Japan
©2023 Readerstacks | Design and Developed by Readerstacks
Go to mobile version