Laravel Simple Qr Code Generator Example

In this tutorial you will learn about the Laravel Simple Qr Code Generator Example and its application with practical example.

In this article, I’ll show you how to generate qr codes with any text, size, color, background color, format like png, eps, svg. In this laravel qr code example, we will be using simple-qrcode package to generate QR codes.The simple-qrcode package is used to generate qr code in your laravel application. The simple-qrcode package has many options for creating qr codes. You can also create qr code for geo, phone number, text message using simple qrcode package. The simple-qrcode package is very easy to install and use.

Before starting with example I assume that you already have fresh laravel 5.8 installation ready, if you have not installed it yet you can follow laravel 5 installation instruction here.

Install Laravel 5.8

First of all we need to create a fresh laravel project, download and install Laravel 5.8 using the below command

Install simple-qrcode Package

In this step, we will install simple-qrcode Package via the composer dependency manager. Use the following command to install simple-qrcode Package.

Register Package

After Installing simple-qrcode package, we need to add service provider and alias in config/app.php file as following.

config/app.php

Basic Usage Of simple-qrcode Package

Qr code with specified string can be generated as follows –

Syntax:-

Simple QR Code :-

Simple Qr code with specified string can be generated using generate() method. Add a simple-qr-code route to your routes/web.php file to return simple QR code as follows –

Here, size() function is used to specify the size of the QR Code. Visit (http://localhost:8000/simple-qr-code) to see the QR code. Scan the QR code and you will see the text. You can also display the QR code in Blade file as follows –

QR Code with Color :-

You can also set color for QR code pattern and the background using color(R, G, B) and backgroundColor(R, G, B) methods.

Add a color-qr-code route to your routes/web.php file to return colored QR code as follows –

Visit (http://localhost:8000/color-qr-code) to see the colored QR code. Or you can simply display the colored QR code in Blade file as follows –

QR Code with Image :-

You can also place an image in QR code using the merge(“file_name.png”) method, this method only accept png files and you also need to format the response back to png.

Add a qr-code-with-image route to your routes/web.php file to return QR code with image as follows –

Visit (http://localhost:8000/qr-code-with-image) to see the QR code with Image merged. Or you can simply display the QR code with Image in Blade file using <img> tag as follows –

Email QR code :-

You can encode QR codes that automatically fill-in email address, subject and body of the email.

Syntax:-

Example:-

QR Code Phone Number :-

You can encode QR codes such that it automatically open up the phone dialer and dial the phone number.

Syntax:-

Example:-

QR Code Text Message :-

You can encode QR codes such that it automatically open up the phone messenger and fill-in phone number or the message body.

Syntax:-

Example:-

QR Code Geo co-ordinates :-

You can encode QR codes such that it automatically open up map application with the specified location.

Syntax:-

Example:-

Create Blade / View Files

In this step, we will create view/blade file to generate and display QR Codes. Lets create a blade file “index.blade.php” in “resources/views/qrcode/” directory and put the following code in it respectively.

resources/views/qrcode/index.blade.php

Create Routes

After this, we need to add following routes in “routes/web.php” file along with a resource route. Lets open “routes/web.php” file and add following route.

routes/web.php

Now we are ready to run our example so lets start the development server using following artisan command –

Now, open the following URL in browser to see the output –

http://localhost:8000/generate-qr-code

Output:-

laravel-5-8-generate-qr-code-tutorial-1

http://localhost:8000/simple-qr-code

Output:-

laravel-5-8-generate-simple-qr-code

http://localhost:8000/color-qr-code

Output:-

laravel-5-8-generate-color-qr-code

http://localhost:8000/qr-code-with-image

Output:-

laravel-5-8-generate-qr-code-with-image

In this tutorial we have learn about the Laravel Simple Qr Code Generator Example and its application with practical example. I hope you will like this tutorial.