How to Generate QR Code in Laravel 9 Example

Published on : July 21,2022
How to Generate QR Code in Laravel 9 Example

Hi Developer,

QR codes are sometimes needed for product identity, inventory and others. Then, how to generate a QRcode? it's easy, we can use Simple QRcode to create QRcode in laravel framework.

Nowadays, we all know how much use the QR code. QR code is simply an encrypted image of some content that is not readable. It needs to use some of the QR code readers.

In this article, we will both learn how to create or generate a QRcode so that when we scan the code it can be directed to SMS, email, website or just to find out what data is behind the QR code.

In this article, we will start from scratch by starting with creating a new laravel project.

This guide will take you through all the necessary steps, which will tell you how to generate various QR codes in the Laravel 9 application using the simple QR code package.

A simple QR code generator gives you the freedom to generate different types of QR Codes in the Laravel 9 app. It gives a simple QrCode wrapper, which is easy to integrate into laravel.

 

How to Generate QR Code in Laravel 9

  • Create Laravel Project
  • Add Database Details
  • Install QR Code Package
  • Register QR Code Service
  • Create Controller
  • Add Route
  • Generate QR Codes in Blade View
  • Run Laravel App

 

Create Laravel Project

First, open Terminal and run the following command to create a fresh Laravel project:

composer create-project --prefer-dist laravel/laravel:^9.0 qr-code-example

 

Note: Laravel 9 requires PHP 8.0 or PHP 8.1.

or, if you have installed the Laravel Installer as a global composer dependency:

laravel new qr-code-example

Add Database Details

After, Installation Go to the project root directory, open the .env file, and set database detail as follow:

DB_CONNECTION=mysql 
DB_HOST=127.0.0.1 
DB_PORT=3306 
DB_DATABASE=<DATABASE NAME>
DB_USERNAME=<DATABASE USERNAME>
DB_PASSWORD=<DATABASE PASSWORD>

Install QR Code Package

Get into the command prompt, type the given command, and begin installing the simplesoftwareio/simple-qrcode package; it profoundly helps create various kinds of QR codes in the laravel app.

composer require simplesoftwareio/simple-qrcode

Register QR Code Service

You have to register the QR code services into the config/app.php file, so open the file and update the providers and alias array with the given below services.

<?php

    return [

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

 

Create Controller

In laravel, all the business logic goes into the controller file, and we need a controller to create one by using the given command.

php artisan make:controller QrCodeController

Next, Open QrCodeController.php and add the following code into the file:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class QrCodeController extends Controller
{
    public function index()
    {
      return view('qrcode');
    }
}

 

Add Route

Now, open the web.php file and add the following routes into it, which are located inside the routes directory:

<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\QrCodeController;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
*/

Route::get('/qrcode', [QrCodeController::class, 'index']);

 

Generate QR Codes in Blade View
We will show you how to use the view file and generate simple and colored QR Codes in laravel.

Now, you are ready to set up a blade view file, hence creating the blade view file within the views folder, after that add the provided code in the resources/views/qrcode.blade.php file.

<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>How to Generate QR Code in Laravel 9</title>
    <meta name="csrf-token" content="{{ csrf_token() }}">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet"/>
</head>

<body>

    <div class="container mt-4">

        <div class="card">
            <div class="card-header">
                <h2>Simple QR Code</h2>
            </div>
            <div class="card-body">
                {!! QrCode::size(300)->generate('https://www.opencodesolution.com/article/how-to-generate-qr-code-in-laravel-9-example') !!}
            </div>
        </div>

        <div class="card">
            <div class="card-header">
                <h2>Color QR Code</h2>
            </div>
            <div class="card-body">
                {!! QrCode::size(300)->backgroundColor(255,90,0)->generate('https://www.opencodesolution.com/article/how-to-generate-qr-code-in-laravel-9-example') !!}
            </div>
        </div>

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

 

Helpers For Generate Different QR Codes
 

BitCoin

This helper generates a scannable bitcoin to send payments.

QrCode::BTC($address, $amount);

//Sends a 0.334BTC payment to the address
QrCode::BTC('bitcoin address', 0.334);

//Sends a 0.334BTC payment to the address with some optional arguments
QrCode::size(500)->BTC('address', 0.0034, [
    'label' => 'my label',
    'message' => 'my message',
    'returnAddress' => 'https://www.opencodesolution.com/'
]);

 

E-Mail

This helper generates an e-mail QRcode that is able to fill in the e-mail address, subject, and body:

QrCode::email($to, $subject, $body);

//Fills in the to address
QrCode::email('foo@bar.com');

//Fills in the to address, subject, and body of an e-mail.
QrCode::email('foo@bar.com', 'This is the subject.', 'This is the message body.');

//Fills in just the subject and body of an e-mail.
QrCode::email(null, 'This is the subject.', 'This is the message body.');

 

Geo
This helper generates latitude and longitude that a phone can read and opens the location in Google Maps or a similar app.

QrCode::geo($latitude, $longitude);

QrCode::geo(37.822214, -122.481769);

 

Phone Number

This helper generates a QR code that can be scanned and then dials a number.

QrCode::phoneNumber($phoneNumber);

QrCode::phoneNumber('555-555-5555');
QrCode::phoneNumber('1-800-Laravel');

 

SMS (Text Messages)

This helper makes SMS messages that can be prefilled with the send-to address and body of the message:

QrCode::SMS($phoneNumber, $message);

//Creates a text message with the number filled in.
QrCode::SMS('555-555-5555');

//Creates a text message with the number and message filled in.
QrCode::SMS('555-555-5555', 'Body of the message');

 

WiFi

This helper makes scannable QR codes that can connect a phone to a WiFi network:

QrCode::wiFi([
    'encryption' => 'WPA/WEP',
    'ssid' => 'SSID of the network',
    'password' => 'Password of the network',
    'hidden' => 'Whether the network is a hidden SSID or not.'
]);

//Connects to an open WiFi network.
QrCode::wiFi([
    'ssid' => 'Network Name',
]);

//Connects to an open, hidden WiFi network.
QrCode::wiFi([
    'ssid' => 'Network Name',
    'hidden' => 'true'
]);

//Connects to a secured WiFi network.
QrCode::wiFi([
    'ssid' => 'Network Name',
    'encryption' => 'WPA',
    'password' => 'myPassword'
]);

 

Run Laravel App

Eventually, use the PHP artisan command to start the laravel server, and also use the given URL to view the app.

php artisan serve

 

Hope it can help you…

 

Categories : Laravel PHP

Tags : PHP Laravel QR Code

Praful Sangani
Praful Sangani
I'm a passionate full-stack developer with expertise in PHP, Laravel, Angular, React Js, Vue, Node, Javascript, JQuery, Codeigniter, and Bootstrap. I enjoy sharing my knowledge by writing tutorials and providing tips to others in the industry. I prioritize consistency and hard work, and I always aim to improve my skills to keep up with the latest advancements. As the owner of Open Code Solution, I'm committed to providing high-quality services to help clients achieve their business goals.


174 Comments

fenofibrate online buy tricor 160mg oral tricor 160mg us


order tadalafil sale sildenafil 100mg price order viagra 50mg online


ketotifen online buy buy generic ketotifen 1mg tofranil 75mg generic


mintop uk erectile dysfunction pills over the counter best erection pills


order precose 25mg for sale buy micronase 2.5mg pills griseofulvin order online


order aspirin online buy aspirin 75 mg without prescription imiquimod order


purchase melatonin sale cerazette sale danazol 100mg generic


order dipyridamole 100mg dipyridamole sale buy pravachol medication


florinef 100 mcg canada pill rabeprazole buy loperamide generic


cost etodolac 600mg order pletal generic cilostazol 100mg drug


order prasugrel 10mg without prescription prasugrel for sale tolterodine online order


buy mestinon paypal buy pyridostigmine 60mg pills maxalt without prescription


buy ferrous sulfate 100mg sale pill ferrous 100 mg buy betapace without a prescription


enalapril 10mg pill purchase casodex buy generic duphalac


buy latanoprost generic zovirax where to buy exelon 6mg sale


betahistine 16 mg generic latanoprost online buy buy probenecid online cheap


purchase premarin without prescription buy generic premarin buy sildenafil 100mg online cheap


buy prilosec sale buy singulair 5mg without prescription buy lopressor 100mg generic


buy telmisartan generic buy plaquenil no prescription buy molnunat pills


order cialis 10mg online cheap viagra cialis buy generic viagra 50mg


cenforce 50mg pill order cenforce online purchase chloroquine generic


buy cheap modafinil modafinil online buy deltasone online cheap


cefdinir online buy generic glucophage order prevacid 30mg without prescription


isotretinoin 20mg pill buy amoxicillin 250mg online purchase azithromycin for sale


buy azithromycin 500mg generic order gabapentin 800mg generic neurontin online order


atorvastatin 20mg ca buy albuterol generic buy amlodipine 10mg pills


win real money online casino generic furosemide 40mg buy generic furosemide over the counter


purchase protonix without prescription zestril us buy cheap generic pyridium


casino games free blackjack online buy albuterol without prescription


black jack card game free real casinos online no deposit ivermectin cost in usa


buy symmetrel for sale buy amantadine generic order avlosulfon pills


empire city casino online purchase amoxiclav for sale cheap levoxyl online


buy clomid 100mg online cheap cheap clomid 50mg order azathioprine 25mg for sale


medrol 4 mg otc aristocort tablet buy aristocort 10mg sale


vardenafil 10mg for sale tizanidine generic generic tizanidine 2mg


buy coversum online cheap buy cheap generic coversyl oral allegra 180mg


phenytoin 100 mg tablet where can i buy oxytrol how to get oxybutynin without a prescription


buy generic lioresal baclofen 10mg drug ketorolac for sale


loratadine ca purchase claritin dapoxetine uk


lioresal online order where can i buy toradol buy generic toradol online


oral fosamax 35mg buy nitrofurantoin 100 mg online cheap order nitrofurantoin 100 mg online cheap


order amaryl for sale order amaryl online buy arcoxia 60mg pills


buy generic propranolol buy generic motrin over the counter plavix online order


order nortriptyline 25mg sale buy cheap generic methotrexate panadol cheap


buy medex pills for sale buy generic maxolon purchase metoclopramide generic


order xenical 60mg online purchase asacol online buy diltiazem 180mg pills


buy famotidine 20mg sale oral tacrolimus buy tacrolimus 1mg without prescription


astelin 10ml price cheap acyclovir 800mg buy avalide generic


purchase esomeprazole pills remeron 30mg brand cost topamax


sumatriptan 25mg cheap buy dutasteride generic buy dutasteride no prescription


order allopurinol 100mg generic purchase rosuvastatin sale buy rosuvastatin 10mg generic


buy ranitidine online cheap zantac ca oral celebrex 200mg


buy cheap buspirone amiodarone for sale amiodarone 100mg generic


cost flomax 0.4mg generic simvastatin 10mg zocor 20mg cost


motilium online buy coreg 25mg drug sumycin without prescription


buy generic aldactone over the counter purchase aldactone without prescription finpecia tablet


commodi in voluptatem aut aut et unde fugit molestiae assumenda sed. quia molestias possimus corrupti nihil harum voluptas eos ex. quibusdam quia voluptate consectetur autem reprehenderit minus sit cu


buy thesis paper editing essays buy a term paper online


diflucan 100mg ca generic ciprofloxacin 1000mg order cipro 1000mg without prescription


buy aurogra medication yasmin uk order estrace online


metronidazole 400mg generic cheap trimethoprim oral keflex 250mg


buy lamotrigine 50mg pill order lamictal 200mg sale buy mebendazole for sale


order cleocin 150mg generic order sildenafil 100mg pill sildenafil 50mg price


retin for sale tadalafil 20mg ca buy avana sale


tamoxifen oral buy betahistine no prescription budesonide generic


buy tadalafil 20mg sale buy tadacip online indocin 50mg canada


buy ceftin 250mg online cheap axetil canada order robaxin 500mg online cheap


order trazodone 50mg online cheap buy generic clindamycin online clindamycin online buy


terbinafine pills order terbinafine play poker online


buy aspirin 75mg without prescription gambling games doubleu casino


speechwriters cost cefixime 200mg suprax 100mg us


my future essay writing custom written papers slot games


order amoxicillin 500mg without prescription order generic biaxin 250mg buy clarithromycin 250mg sale


buy rocaltrol generic order labetalol 100mg sale fenofibrate 200mg drug


buy generic catapres for sale clonidine 0.1 mg brand buy spiriva 9mcg for sale


best acne pills prescription antibiotics for pimple pills order oxcarbazepine 300mg generic


order minocycline terazosin 5mg drug order requip pill


alfuzosin for sale online is claritin stronger than benadryl nausea medication for chemo patients


online treatment for insomnia jak inhibitor approved for alopecia weight loss drugs prescription online


letrozole 2.5 mg brand brand abilify 20mg buy aripiprazole pills for sale


free nhs stop smoking service new medication for smoking cessation types of pain medications list


buy provera 5mg pills praziquantel over the counter hydrochlorothiazide 25 mg for sale


get herpes prescription online over the counter preventative inhaler is ozempic fda approved for prediabetes


periactin for sale online buy periactin without a prescription ketoconazole 200mg ca


best antifungal pills fungus on skin pictures types safest high blood pressure meds


duloxetine ca buy glucotrol pill buy provigil 100mg for sale


alternative treatment for gastritis list of medicine for stomach best otc treatment for uti


promethazine oral ed pills online stromectol generic


buy neli pills online best pain reliever for prostatitis can cialis cause erectile dysfunction


prednisone 40mg us buy deltasone 40mg online cheap amoxicillin price



acid reducer strongest to weakest does cyclizine need a prescription medicine to stop flatulence


purchase azithromycin buy generic omnacortil over the counter buy gabapentin pill


order actigall 150mg pill cetirizine generic how to buy cetirizine


strattera 10mg drug zoloft 100mg pills sertraline 50mg uk


order lasix 100mg sale lasix usa buy ventolin no prescription


lexapro 20mg for sale fluoxetine 20mg pill naltrexone cost


purchase augmentin generic buy cheap levothyroxine order serophene sale


combivent 100mcg for sale cost combivent 100 mcg buy zyvox 600 mg generic


generic nateglinide 120 mg capoten online buy buy candesartan online


starlix over the counter atacand over the counter buy candesartan 16mg generic


vardenafil 20mg oral cheap hydroxychloroquine order hydroxychloroquine 200mg generic


buy tegretol 400mg oral ciplox 500mg lincocin cheap


buy cenforce 50mg without prescription order cenforce 50mg without prescription glucophage 500mg cheap


order cefadroxil 250mg pills purchase lamivudine sale combivir generic


lipitor 10mg us order amlodipine generic zestril 10mg brand


cabergoline 0.5mg sale oral claritin priligy 60mg cost


purchase medrol sale desloratadine 5mg ca desloratadine 5mg tablet


where can i buy misoprostol how to get diltiazem without a prescription buy diltiazem 180mg generic


order nootropil 800mg for sale clomipramine online order buy anafranil 50mg


order acyclovir pill buy acyclovir crestor 10mg drug


sporanox 100 mg cost order progesterone sale tindamax 500mg ca


ezetimibe pills purchase sumycin for sale order sumycin generic


zyprexa 10mg pill zyprexa pills purchase valsartan pills


order flexeril 15mg online cheap buy cyclobenzaprine 15mg without prescription buy toradol generic


colchicine 0.5mg generic order colcrys 0.5mg sale methotrexate 5mg usa


teenage acne treatment for girls buy generic isotretinoin online popular prescription acne medication


allergy pills for rash buy methylprednisolone generic allergy pills non drowsy


strongest antacid over counter buy allopurinol 100mg without prescription



prednisone 5mg uk order prednisone


prescription antacid medication list buy roxithromycin generic


best acne treatment for boys prednisone for sale adult acne medication prescription


allegra side effects flixotide price non drowsy allergy medication canada


top rated heartburn prescription order quinapril 10 mg


oral isotretinoin 40mg accutane 40mg tablet accutane 10mg over the counter


amoxicillin 1000mg sale order amoxil 250mg online amoxicillin 500mg tablet


buy sleep aids online meloset over the counter


order azithromycin 250mg generic zithromax usa brand azithromycin


gabapentin 100mg us gabapentin drug


order azithromycin 250mg without prescription buy azipro 250mg sale buy azipro generic


buy generic lasix 100mg buy generic lasix


order omnacortil generic buy omnacortil sale prednisolone order


amoxicillin 1000mg us buy amoxil 1000mg sale amoxil order online


monodox online buy purchase monodox online


strongest over the counter antihistamine albuterol 4mg pill buy ventolin generic


buy generic augmentin buy augmentin 1000mg sale


buy levothyroxine medication buy generic synthroid 100mcg cheap levothyroxine


vardenafil 10mg generic buy levitra generic


tizanidine online tizanidine ca buy tizanidine tablets


buy serophene generic clomiphene pill cost clomid 50mg


deltasone 20mg drug buy prednisone 10mg generic deltasone 40mg generic


buy rybelsus 14mg generic order semaglutide 14mg online buy semaglutide 14mg sale


accutane pills isotretinoin 40mg over the counter buy accutane 10mg without prescription


buy semaglutide without prescription semaglutide 14mg oral order rybelsus 14mg online cheap


purchase albuterol inhalator buy ventolin without a prescription best antihistamine for allergic rhinitis


order amoxicillin generic amoxicillin 1000mg usa oral amoxicillin 500mg


zithromax online buy order zithromax for sale purchase zithromax without prescription


levoxyl generic synthroid 150mcg without prescription oral levothroid


cheap prednisolone tablets prednisolone 10mg drug buy prednisolone no prescription


online casino games for real money best casino online slot games


purchase levitra sale buy vardenafil without a prescription purchase levitra online


lyrica tablet lyrica pills buy cheap lyrica


cost hydroxychloroquine buy plaquenil 200mg online cheap generic hydroxychloroquine 200mg


aristocort ca buy aristocort medication buy aristocort 4mg online


order tadalafil 20mg generic tadalafil 20mg cheap buy generic tadalafil 40mg


cheap clarinex 5mg buy desloratadine without prescription clarinex 5mg tablet


cenforce drug cenforce 50mg brand cenforce 100mg without prescription


buy loratadine generic claritin over the counter loratadine 10mg cheap


chloroquine 250mg over the counter aralen 250mg brand aralen 250mg generic


oral priligy dapoxetine sale cost misoprostol 200mcg


oral orlistat 60mg order orlistat 60mg for sale buy diltiazem sale


buy atorvastatin generic buy lipitor pills for sale lipitor 40mg tablet


cost zovirax zovirax over the counter zyloprim 300mg brand


buy norvasc cheap buy generic amlodipine amlodipine generic


buy zestril 5mg generic lisinopril 5mg oral lisinopril 2.5mg usa


crestor without prescription purchase crestor generic buy ezetimibe tablets


oral omeprazole order prilosec prilosec 20mg pill


domperidone online buy cheap sumycin 500mg order sumycin 250mg pills


brand metoprolol metoprolol 50mg cheap buy metoprolol 100mg pill


cyclobenzaprine online order ozobax sale order ozobax generic


purchase atenolol pills buy atenolol 50mg online order tenormin 50mg online


buy cheap ketorolac toradol drug cost colcrys


buy medrol 4mg where to buy medrol without a prescription purchase methylprednisolone


Leave a comment

We'll never share your email with anyone else. Required fields are marked *

Related Articles

Access specifier in php
Praful Sangani By Praful Sangani - July 20,2022