Laravel

How to Generate QR Code in Laravel 9

Hello Laravel Friends,

In today’s blog file, I will explain How to Generate a QR Code in Laravel 9.

QR code can be a valuable addition to your Laravel project. Assigning a QR code to each product helps to efficiently manage inventory and simplify the tracking process.

Creating a QR code in Laravel 9 can be achieved using a package called “Simple-QR-Code.” This package provides a simple and straightforward way to generate QR codes for various content types. Here, I’ll guide you through the process step by step. 

Steps to Generate QR Code in Laravel 9:

Step 1: Create a Laravel project using the below command

composer create-project laravel/laravel:^9.0 your-project-name

Step 2: Now install the package simplesoftwareio/simple-qrcode to generate the QR code

Use the below command 

composer require simplesoftwareio/simple-qrcode "~4"

Step 3: Add the below lines in the service provider

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

And aliases in config/app.php

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

Step 4: Create one route in the web.php file and create one blade file in the view folder to show the QR code

path – routes/web.php 

Route::get('/', function () {
    return view('welcome');
});

path – resources/views/welcome.blade.php

<!DOCTYPE html>
<html>

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

    <title>Laravel QR Blog</title>

</head>

<body class="antialiased">
    <div>
        {!! QrCode::generate('Make me into a QrCode!') !!}
    </div>
</body>

</html>

Now, you can run it in your browser and check it. 

Output: 

Step 5: You can change the color of the QR code using the below code 

{!! QrCode::size(150)->color(75, 0, 130)->generate('Make me into a QrCode!') !!}

Output: 

Conclusion:

Hence, using the above method, you can easily generate a QR code in your Laravel 9 application and change its color as per your requirement. If you have any doubts about generating the QR code for your Laravel application, let me know through the comment section, or you can connect with experienced Laravel Developers to further customize QR codes for your Laravel project.

Happy Coding!

Click to rate this post!
[Total: 10 Average: 3.5]
Bharat Desai

Bharat Desai is a Co-Founder at MageComp. He is an Adobe Magento Certified Frontend Developer ? with having 8+ Years of experience and has developed 150+ Magento 2 Products with MageComp. He has an unquenchable thirst to learn new things. On off days you can find him playing the game of Chess ♟️ or Cricket ?.

Recent Posts

How to Add Tooltip in Checkout Shipping Field in Magento 2?

Hello Magento Friends, In today’s blog, I will explain How to Add Tooltip in Checkout…

2 days ago

How to Integrate and Use MongoDB with Laravel?

MongoDB is a popular NoSQL database that offers flexibility and scalability when handling modern web…

3 days ago

NodeJS | Callback Function

In NodeJS, callbacks empower developers to execute asynchronous operations like reading files, handling requests, and…

4 days ago

How to Show SKU in Order Summary in Magento 2?

Hello Magento Friends, In today’s blog, we will learn How to Show SKU in Order…

6 days ago

Best Colors to Use for CTA Buttons

The "Buy Now" and "Add to Cart" buttons serve as the primary call-to-action (CTA) elements…

1 week ago

Magento 2: How to Save Custom Field Value to quote_address for Multi-Shipping Orders

Hello Magento Friends, In Magento 2, the checkout process allows customers to choose multiple shipping…

1 week ago