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 file_get_contents Post and Get Request with Headers in Laravel

file_get_contents Post and Get Request with Headers in Laravel ?

June 13, 2022June 13, 2022

In this article i will show you to send file_get_contents post and get request with headers in laravel. As we know file_get_contents is php inbuilt core function used to access the local file and remote URLs. File_get_contents is used to read the file in different modes and to send the…

Read More
Php Custom Error pages in laravel

How to create a custom 404 page in Laravel 8 ?

December 28, 2021December 28, 2021

Laravel provides its inbuilt 404 error page and shows text 404 page not found but we want more customization and better ui for 404 page so in this article i will show yo to customize the 404 not found error page in laravel. This article will cover you to create…

Read More
Php Laravel session

How to set and get session in Laravel 8?

November 8, 2021November 17, 2021

Laravel has its own class to manage the session using the file system, redis, array, cookie and database. Session are used to keep the information about the user across the multiple request. As we know PHP is a server side language and all information lost after the response, so keep…

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

  • 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 Resilience of Nature: How Forests Recover After Fires
  • Understanding Laravel Cookie Consent for GDPR Compliance
  • Understanding High Vulnerabilities: A Critical Overview of the Week of May 12, 2025
  • Installing a LAMP Stack on Ubuntu: A Comprehensive Guide
  • Understanding High Vulnerabilities: A Deep Dive into Recent Security Concerns
©2023 Readerstacks | Design and Developed by Readerstacks
Go to mobile version