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
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
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
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.
To change the image type, we can use following method,
QrCode::format(‘png’);
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'));
This package also provides the helpers which can help user to perform particular action when they scan the Qrcode.
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.');
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);
This helper can open the phone dialer on the device to dial the number which is attached with Qrcode.
QrCode::phoneNumber('342-456-1235');
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’);
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.
Today we are going to learn about managing multiple PHP versions on ubuntu with xampp.…
Let's understand about how to use coding to improve your website's SEO. In today’s computerized…
Let's understand the most important linux commands for web developers. Linux, as an open-source and…
Today we are going to discuss top 75+ Laravel interview questions asked by top MNCs.Laravel,…
Today we will discuss about the Mailtrap integration with laravel 10 .Sending and receiving emails…
Today we are going to integrate FCM (Firebase Cloud Messaging) push notifications with ionic application.Firebase…