Laravel 8 Generate QR Code Example

In this tutorial you will learn about the Laravel 8 Generate QR Code Example and its application with practical example.

Laravel 8 Generate QR Code Example

In this tutorial, we will learn to generate QR Code in laravel 8.  In this step by step tutorial I’ll show you how to generate qr codes with any text, size, color, background color, format like png, eps, svg. In this laravel 8 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.

Generate QR Code In Laravel 8 Tutorial

In this step by step tutorial we generate qr codes using simple-qrcode package.

  • Install Laravel 8
  • Setup Database Credentials
  • Install simple-qrcode package
  • Define Route
  • Create Blade View
  • Start Development Server
  • Conclusion

Install Laravel 8

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

Install Laravel 8 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

How to use simple-qrcode Package In Laravel 8

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 –

Output:-

Laravel 8 Generate QR Code Example

Laravel 8 Generate Simple QR Code

Below is an example of generating simple qr code in laravel 8 using simple qr code package. We have added following route in the web.php file to generate simple qr code in laravel.

Now, visit the following url in browser to view the simple qr code generated laravel.

Output:-

How to Generate QR Code In Laravel 8

Laravel 8 Generate QR Code With Background Color

Below is an example of generating qr code with background color in laravel 8 using simple qr code package. We have added following route in the web.php file to generate qr code with background color.

Now, visit the following url in browser to view the qr code with background color in laravel.

Output:-

Laravel 8 Generate QR Code with background color

Laravel 8 Generate QR Code With Image

Below is an example of generating qr code with image in laravel 8 using simple qr code package. We have added following route in the web.php file to generate qr code with image.

Now, visit the following url in browser to view the qr code with image generated in laravel.

Output:-

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

In this tutorial we have learned how to generate qr code in laravel 8. I have also shown you how to implement a laravel 8 qr code example.

In this tutorial we have learn about the Laravel 8 Generate QR Code Example and its application with practical example. I hope you will like this tutorial.