Laravel QR Code Generator Example

Share Me
  •  
  •  
  •  
  • 1
  •  
  •  
  •  
  •  
  •  
  •  
  •  
    1
    Share

Today now in this blog, I will explain with you how to generat qr code in laravel application. Now here i will share with you a article about how to create qr code by using simple-qrcode in laravel application.

Here i will create a easy example of qr code generator in laravel Application. simple-qrcode is a very good composer package for generate qr code in our laravel application. So now in this example I will show you how to send sms or email also with generated qr code. We can also create qr code for geo, phone number, text message by using simple qrcode package.

Simple qr codes package is a very easy to install and also very easy to use. Simple qr code package has provide us many functions for generating qr codes. So now in this example i will show you how to use this package and generate qr codes.

Install Laravel Application

Here i am going from scratch, So i need a fresh Laravel application so by using bellow command, So now open your terminal OR command prompt and then run bellow command:

composer create-project --prefer-dist laravel/laravel blog
Install simplesoftwareio/simple-qrcode

Now here in this step need to install the simplesoftwareio/simple-qrcode Package

composer require simplesoftwareio/simple-qrcode
Add providers and aliases

So after the install package add providers and aliases in the “config/app.php” file.

following path: config/app.php

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

Simple Qr code

So now in this step need to create simple Qr Code. Now i will add a route and it return QR code. Simply add the following code in your web.php file.

following path: routes/web.php

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

output qr code

Laravel QR Code Generator
Qrcode With Color

So now in this step we need to create color Qr Code. Now i will add a route and return QR code. Simply add the following code in your web.php file.

following path: routes/web.php

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

output qr code

Laravel QR Code Generator
QR Code with Image

Now in this step i will create Image Qr Code. Here i will add a route and it return QR code. So it is simply add the following code in our web.php file.

following path: routes/web.php

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

So now here this step i will create email Qr Code. Now i will add a route and return QR code. So it simply add the following code in your web.php file.

following path: routes/web.php

Route::get('qrcode-with-special-data', function() {
     return \QrCode::size(500)
                 ->email('codingspoint@gmail.com', 'Welcome to nicesnippets!', 'This is !.');
 });
PhoneNumber QR code :

In Blow this step i will create PhoneNumber Qr Code. So here i will add a route and it will return QR code. Simply add the following code in our web.php file.

following path: routes/web.php

Route::get('qrcode-with-special-data', function() {
     return \QrCode::phoneNumber('111-222-6666');
 });
QR Code Text Message

So now the blow in this step i will create a Text Message Qr Code. Here i will add a route and it will return QR code. It will Simply add the following code in our web.php file.

following path: routes/web.php

Route::get('qrcode-with-special-data', function() {
     return \QrCode::SMS('01797245860', 'Body of the message');;
 });

Read Also : Laravel Pagination with Ajax Example

Thank you read.Hope it will help you. Also follow on facebook

About Shahriar Sagor

My name is Shahriar sagor. I'm a developer. I live in Bangladesh and I love to write tutorials and tips that will help to other Developer's. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.

View all posts by Shahriar Sagor →