Laravel 7/ 6 QR Code Generator Example

Laravel 6 , Laravel , Laravel 7

Nicesnippets

42780

04-02-2020


Laravel 7/ 6  QR Code Generator Example

Hi Guys

Today I will explain how to generat qr code in laravel 7/ 6. we will share with you how to create qr code using simple-qrcode in laravel 7/ 6.

i will create easy example of qr code generator in laravel 7/ 6

simple-qrcode is a composer package for generate qr code in your laravel application.In this example we will show you how to send sms and email with generated qr code, you can also create qr code for geo, phone number, text message using simple qrcode package.

Simple qr codes package is very easy to install and use. Simple qr code package has provide many functions for generating qr codes. In this example we will learn how to use this package and generate qr codes.

Install Laravel 7/ 6 Application


we are going from scratch, So we require to get fresh Laravel application using bellow command, So open your terminal OR command prompt and run bellow command:

composer create-project --prefer-dist laravel/laravel blog

Install simplesoftwareio/simple-qrcode

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

composer require simplesoftwareio/simple-qrcode

Add providers and aliases

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

In this step create simple Qr Code. We 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', function () {

return QrCode::size(300)->generate('A basic example of QR code! Nicesnippets.com');

});

output qr code

Qrcode With Color

In this step create color Qr Code. We 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

QR Code with Image

Now this step create Image Qr Code. We 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-image', function () {

$image = \QrCode::format('png')

->merge('https://www.nicesnippets.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');

});

output qr code

Email QR code :

Here this step create email Qr Code. We 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-special-data', function() {

return \QrCode::size(500)

->email('[email protected]', 'Welcome to nicesnippets!', 'This is !.');

});

PhoneNumber QR code :

Blow this step create PhoneNumber Qr Code. We 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-special-data', function() {

return \QrCode::phoneNumber('111-222-6666');

});

QR Code Text Message

Blow this step create Text Message Qr Code. We 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-special-data', function() {

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

});

It will help you...