Laravel

Example of Laravel QR Code generator with Laravel 5.8

Share your learning

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.

Satpal

Recent Posts

How to Switch PHP Versions in XAMPP Easily: Managing Multiple PHP Versions on Ubuntu

Today we are going to learn about managing multiple PHP versions on ubuntu with xampp.…

1 year ago

How to Use Coding to Improve Your Website’s SEO Ranking?

Let's understand about how to use coding to improve your website's SEO. In today’s computerized…

1 year ago

Most Important Linux Commands for Web Developers

Let's understand the most important linux commands for web developers. Linux, as an open-source and…

1 year ago

Top 75+ Laravel Interview Questions Asked by Top MNCs

Today we are going to discuss top 75+ Laravel interview questions asked by top MNCs.Laravel,…

1 year ago

Mailtrap Integration for Email Testing with Laravel 10

Today we will discuss about the Mailtrap integration with laravel 10 .Sending and receiving emails…

1 year ago

Firebase Cloud Messaging (FCM) with Ionic 6: Push Notifications

Today we are going to integrate FCM (Firebase Cloud Messaging) push notifications with ionic application.Firebase…

1 year ago