Laravel 7/6 QR Code Generator Example

Laravel 7/6 QR Code Generator Example

Laravel 7/6 generate Bar/QR code example. We would love to share with you how to generate (create) Bar/QR code using simple-QRcode in laravel projects. You can simply create (generate) QR codes with text, size, color, background color, format like png, eps, SVG.

Simple QR/Bar code is a composer package to generate QR code in your laravel application. In this example we will show you how you can send SMS and email of generated QR/Bar code, You can also create QR/Bar code for geo, phone number, text message using a simple QRcode package.

Simple Bar/QR codes package is very easy to install and use. Simple QR code package has provided many functions (options) for creating (generating) QR codes. In this example, we will learn how to use this package and generate QR codes.

if you want to know how to generate or create pdf in laravel you can read this => Generate OR Create PDF In Laravel Example

Generate QR/Bar codes in Laravel

Follow the below steps and easily create or generate QR codes in laravel Projects.

  • Install Laravel Fresh Setup
  • Set database Credentials In .env File
  • Install simple-QRcode Package
  • Register Package
  • Test Qr Code
  • Conclusion

1. Install Laravel Fresh Project

We need to install Laravel fresh application setup using below command, Open your command prompt and run the below command :

composer create-project --prefer-dist laravel/laravel Laravel-QR-Code

2. Set database Credentials In .env File

Next step, you have downloaded the fresh new setup of laravel in your system. So set the database credentials in your application. Let’s open your project .env file and set the database credentials here.

 DB_CONNECTION=mysql 
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=here your database name here
DB_USERNAME=here database username here
DB_PASSWORD=here database password here

3. Install simple-QRcode Package

In this step, we will install a simple-QRcode package for the QR code generator, go to terminal and use the below command for install QR code package in laravel based application.

composer require simplesoftwareio/simple-qrcode

4. Register Package

After successfully install a simple QR code package in the laravel app. Next, open config/app.php file and add service provider and aliases.

 //config/app.php

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

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

5. Test Qr Code

Now we will generate and test qr code in laravel application.

Simple Qr code :

We will add a route and return QR code. Simply add the following code in your web.php file.

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

size() function is used to specify the size of QR. When we hit the route /QRcode, we get the QR code as below :

php qr code
QR Code with Color :

Now We can change the color of QR code. Go to route web.php file and specify this route.

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

The above code output a QR code shown below :

color qr code
QR Code with Image :

We will also place an image inside the QR code. Go to route web.php file and specify this route.

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

The above code output a QR code as shown below :

image qr code
Email QR code :

We can also automatically fill email, subject, and body when scanned.

Route::get('qrcode-with-special-data', function() {
return \QrCode::size(500)
->email('[email protected]', 'Welcome to Tutsmake!', 'This is !.');
});
QR Code Phone Number :

This package also helps to dial a number when QR code is scanned.

QrCode::phoneNumber('111-222-6666');
QR Code Text Message

We can prefilled phone number and text messages when scanned the QR code.

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

Conclusion

In this laravel simple QR code tutorial – we have successfully installed and configure a simple QR code package in laravel application. We have also learned how to create (generate) simple QR code in laravel application with send SMS text and email to QR code.

Recommended Laravel Tutorial:

  1. Laravel Tutorial From Scratch | Step By Step
  2. Laravel 7, 6 Ajax CRUD(DataTables Js) Tutorial Example
  3. Laravel 7, 6 – Ajax CRUD (Operation) Application Example
  4. Laravel 7, 6 Angular JS CRUD Example Tutorial
  5. Upload Files/Images to Amazon s3 Cloud Using Laravel 6 Filesystem
  6. Laravel 7,6 CKEditor with Image Upload
  7. Ajax Image Upload In Laravel Tutorial Example From Scratch
  8. Laravel 6,7 Intervention Upload Image Using Ajax – Example
  9. Laravel Upload Image to Database with Validation
  10. Send Email Example Laravel
  11. Simple Generator or Create Qr Code Example Laravel
  12. Laravel Custom Cron Schedule Example Tutorial
  13. Laravel 6,7 Github Login Example
  14. Laravel 7, 6 Currency Exchange Rate Calculator
  15. Charts Example Laravel Tutorial | Pie Chart
  16. Laravel: Create Newsletter Example Tutorial
  17. Laravel 7, 6 Highcharts Example Tutorial

AuthorAdmin

My name is Devendra Dode. I am a full-stack developer, entrepreneur, and owner of Tutsmake.com. I like writing tutorials and tips that can help other developers. I share tutorials of PHP, Python, Javascript, JQuery, Laravel, Livewire, Codeigniter, Node JS, Express JS, Vue JS, Angular JS, React Js, MySQL, MongoDB, REST APIs, Windows, Xampp, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL and Bootstrap from a starting stage. As well as demo example.

Leave a Reply

Your email address will not be published. Required fields are marked *