Laravel PHP Simple Qr Codes Generate

In this laravel qr code tutorial, we will share with you how to generate (create) qr code using simple-qrcode in laravel 5.7 & 5.8. you can simply create (generate) qr codes with text, size, color, background color, format like png, eps, svg. This example also work with laravel version 5.8 , 5.7 & 5.6 .

simple-qrcode is a composer package for generate qr code in your laravel 5.7 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 (options) for creating (generating) qr codes. In this example we will learn how to use this package and generate qr codes.

Content

  • Install Laravel Fresh Setup
  • Configuration .env file
  • Install simple-qrcode Package
  • Regiser Package
  • Test Qr Code
  • Conclusion

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 LaravelQR

Install simple-qrcode Package

In this step, we will install simple-qrcode package for 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

Register Package

After successfully install simple qr code package in laravel app. Next open config/app.php file and add service provider and aliase.

 //config/app.php

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

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

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 install and configure simple qr code pakcage in laravel application. We have also learned how to create (generate) simple qr code in lara app with send sms text and email to qr code.

If you want to remove public or public/index.php from URL In laravel, Click Me

AuthorDevendra Dode

Greetings, I'm Devendra Dode, a full-stack developer, entrepreneur, and the proud owner of Tutsmake.com. My passion lies in crafting informative tutorials and offering valuable tips to assist fellow developers on their coding journey. Within my content, I cover a spectrum of technologies, including 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. Whether you're starting out or looking for advanced examples, I provide step-by-step guides and practical demonstrations to make your learning experience seamless. Let's explore the diverse realms of coding together.

3 replies to Laravel PHP Simple Qr Codes Generate

  1. How to save this qr image to a database

    • You can save the path of generated QR code into your database table

    • You can use base64_encode() and save db as text 🙂

Leave a Reply

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