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 ShareSend Message to WhatsApp in Laravel PHP

How to Share/Send Message to WhatsApp in Laravel PHP ?

March 16, 2022March 16, 2022

Sharing or sending message to whatsapp from a website using a link is simple as possible. In this article we will not use any package or third party tool to share the url or message to whatsapp. Whatsapp itself provide to share or send message using the url so in…

Read More

How to increase maximum file upload size in php ?

August 24, 2021August 24, 2021

Php is the most used language in web. sometimes it required to upload the files which is greater then 2 mb. In php default upload size is 2 mb and if we wanted to increase it then we have multiple ways to change the size of uploading. 1. Change from…

Read More
Php Laravel password hash and check

How to create hash password in laravel 8 ?

January 26, 2022January 26, 2022

Laravel provides robust security features and one of them are hash password which is not decryptable. For hashing the password laravel use secure Bcrypt and Argon2 hashing for storing user passwords. Password encrypted with Bcrypt can not be decrypt since it uses key to generate the hashed string and irreversible…

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

  • 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

  • Mapping Together: The Vibrant Spirit of OpenStreetMap Japan
  • Understanding High Vulnerabilities: A Deep Dive into the Weekly Summary
  • Building a Million-Dollar Brand: The Journey of Justin Jackson
  • Mastering Schedule Management with Laravel Zap
  • The Resilience of Nature: How Forests Recover After Fires
©2023 Readerstacks | Design and Developed by Readerstacks
Go to mobile version