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 Laravel Redirect from Http to Https Secure URL

Laravel Redirect from Http to Https Secure URL

August 26, 2022March 16, 2024

To redirect from http to https secure url in laravel we can achieve by multiple ways. While deploying application to server we need to make our website secure and robust so attackers can not attack easily on website. In this tutorial we will learn to redirect the http to https…

Read More
Php How to Send Mail with Attachment(PDF, docs,image) in Laravel

How to Send Mail with Attachment(PDF, docs,image) in Laravel 8 /9 ?

May 10, 2022May 10, 2022

Attachment with mail is very important feature of mail by which we can attach any document with our email , for example in some scenarios we want to send the invoice to user mail or some guideline to user after registration. So in this article we will learn to use…

Read More
Php laravel custom validation

How to make custom validation in Laravel 8 ?

October 19, 2021October 28, 2021

In this tutorial we will learn to implement custom validation rule in Laravel 8. Laravel has too many validation rules but sometime we feel some rules are missing according to our project need. so, in this article we will learn to implement custom reusable validation rule and implement the username…

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

  • 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

  • Understanding High Vulnerabilities: A Deep Dive into Recent Security Concerns
  • Understanding High Vulnerabilities in Software: A Week of Insights
  • Blocking Spam Requests with LaraGuard IP: A Comprehensive Guide
  • Enhancing API Development with Laravel API Kit
  • Exploring the Future of Web Development: Insights from Milana Cap
©2023 Readerstacks | Design and Developed by Readerstacks
Go to mobile version