Example of Laravel QR Code generator with Laravel 5.8

Hey dude, today I am going to show you how to use Laravel QR code generator with Laravel 5.8 because I am here with a complete tutorial about a simple QR Code generator package with Laravel.
So, let’s begin
Getting start with Laravel qr code generator package
Step 1: Laravel installation
First step will be to install Laravel. If you want to use this QR code generator with an existing Laravel project, you can proceed with the second step.
To know more about Laravel installation, you can follow my Laravel Installation tutorial.
Or use the following composer command.
composer create-project --prefer-dist laravel/laravel project_name
Step 2: Simple-qrcode generator package installation
Now the next step is to install simple QR code package and we are going to use simple-qrcode package of simplesoftware.io. You can get the complete documentation of it at official website of this package.
Run the following composer command to install this package.
composer require simplesoftwareio/simple-qrcode
Step 3: Examples of qrcode generator package?
Basic syntax:
QrCode::size(px)->generate(string, path);
QrCode generates a square SVG image by default and size in pixels. The generate method will accept two parameters first will be string and second will be a path with the image name to save the image.
Image type:
To change the image type, we can use following method,
QrCode::format(‘png’);
Use in controller:
To use this package in controller, which is very common use, you can use its namespace like below,
use SimpleSoftwareIO\QrCode\Facades\QrCode; $qrcode = QrCode::size(500) ->format('svg') ->generate($gen_str, storage_path('app/public/qrcodes/'.str_slug($tasks['title']).'.svg'));
Best features of Laravel qrcode generator package
This package also provides the helpers which can help user to perform particular action when they scan the Qrcode.
E-mail helper:
Email helper can generate the Qrcode to compose the email with all necessary details like address, subject and body.
QrCode::email('satpalbhardwaj@gmail.com', 'Testing Subject', 'Testing message body.');
Geo helper:
This helper can generate Qrcode with latitude and longitude that can open the google map or other map app on the device with location.
QrCode::geo($latitude, $longitude);
Phone Number helper:
This helper can open the phone dialer on the device to dial the number which is attached with Qrcode.
QrCode::phoneNumber('342-456-1235');
Text message helper:
SMS helper method works same like email helper does. This helper can generate Qrcode with prefilled message details and device will perform the action when scan the Qrcode.
QrCode::SMS('342-456-1235', ‘Text Message body’);
WiFi helper:
This is also very interesting use of this package Wifi connector. This helper can help us to connect with wifi when scan the QrCode.
QrCode::wiFi([ 'encryption' => 'WPA/WEP', 'ssid' => 'SSID of the network', 'password' => 'Network Secret or password', 'hidden' => hidden SSID or not.' ]);
That’s it, laravel qr code generator with simple package.
If you like the article please comment and share it. I will try to serve my best.