How to Generate Various QR Codes in Laravel 8

How to Generate Various QR Codes in Laravel 8

Laravel 8 QR code generate example. In this tutorial, you will learn how to generate/create QR code using simple-QRcode or simplesoftwareio/simple-qrcode 8 in laravel 8 app. And as well as learn how to generate QR codes with text, size, color, background color, format like png, eps, SVG.

And this tutorial will guide you on how to generate different types of qr codes in laravel 8 app. And also these qr codes via SMS and email.

Note that, Simple Bar/QR codes package is very easy to install and use in laravel 8 app. Simple QR code package has provided many functions (options) for creating (generating) QR codes.

How to Generate Various QR Codes in Laravel 8

  • Step 1 – Install Laravel 8 App
  • Step 2 – Connecting App to Database
  • Step 3 – Install simple-QRcode Package
  • Step 4 – Configure Simple QR Code Package
  • Step 5 – Add Routes
  • Step 5 – Run Development Server

Step 1 – Install Laravel 8 App

First of all, open terminal and execute the following command on terminal to install or download Laravel 8 app:

composer create-project --prefer-dist laravel/laravel Laravel-QR-Code

Step 2 – Connecting App to Database

In this step, open .env and configure database details for connecting app to database:

 DB_CONNECTION=mysql 
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=here your database name here
DB_USERNAME=here database username here
DB_PASSWORD=here database password here

Step 3 – Install simple-QRcode Package

In this step, Execute the following command terminal to install simple-QRcode package for generate different types of QR code generator in laravel 8 app:

composer require simplesoftwareio/simple-qrcode

Step 4 – Configure Simple QR Code Package

After successfully install a simple QR code package in the laravel app. Next, open config/app.php file and add service provider and aliases.

 //config/app.php

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

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

Step 5 – Add Routes

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

Simple Qr code :

Add a route and return QR code. Simply add the following code in your web.php file.

Route::get('qrcode', function () {
return QrCode::size(300)->generate('A basic example of QR code!');
});

size() function is used to specify the size of QR. When you hit the route /QRcode, you get the QR code as below :

php qr code
QR Code with Color :

Now, you can change the color of QR code. Go to route web.php file and specify this route.

Route::get('qrcode-with-color', function () {
return \QrCode::size(300)
->backgroundColor(255,55,0)
->generate('A simple example of QR code');
});

The above code output a QR code shown below :

color qr code
QR Code with Image :

Now, place an image inside the QR code. Go to route web.php file and specify this route.

Route::get('qrcode-with-image', function () {
$image = \QrCode::format('png')
->merge('images/laravel.png', 0.5, true)
->size(500)->errorCorrection('H')
->generate('A simple example of QR code!');
return response($image)->header('Content-type','image/png');
});

The above code output a QR code as shown below :

image qr code
Email QR code :

You can use the following routes to send qr code in email:

Route::get('qrcode-with-special-data', function() {
return \QrCode::size(500)
->email('[email protected]', 'Welcome to Tutsmake!', 'This is !.');
});
QR Code Phone Number :

This package also helps to dial a number when QR code is scanned.

QrCode::phoneNumber('111-222-6666');
QR Code Text Message

You can prefilled phone number and text messages when scanned the QR code.

QrCode::SMS('111-222-6666', 'Body of the message');

Step 6 – Run Development Server

Now, execute the following command on terminal to start development server:

php artisan serve

Conclusion

In this laravel 8 simple QR code tutorial – You have successfully installed and configure a simple QR code package in laravel application. We have also learned how to create (generate) simple QR code in laravel application with send SMS text and email to QR code.

Recommended Laravel Posts

AuthorAdmin

My name is Devendra Dode. I am a full-stack developer, entrepreneur, and owner of Tutsmake.com. I like writing tutorials and tips that can help other developers. I share tutorials of PHP, Python, Javascript, JQuery, Laravel, Livewire, Codeigniter, Node JS, Express JS, Vue JS, Angular JS, React Js, MySQL, MongoDB, REST APIs, Windows, Xampp, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL and Bootstrap from a starting stage. As well as demo example.

Leave a Reply

Your email address will not be published. Required fields are marked *