Laravel 9 Generator QR Code Tutorial with Example

10-Apr-2023

.

Admin

Laravel 9 Generator QR Code Tutorial with Example

Hi friends,

Today, I am explain laravel 9 generator QR code tutorial with an example. In this tutorial, we will learn how to generate/create QR code using simple-QRcode or simplesoftwareio/simple-qrcode in laravel 9 app. And as well as learn how to generate QR codes with text, size, color, background color, format like png, eps, SVG. We will learn to generate QR Code in laravel 9. The simple-qrcode package is used to generate QR codes in your laravel 9 application.

QR codes package is very easy to install and also very easy to use. A simple QR code package has provided us with many functions for generating QR codes. So following this example is how to generate QR codes.

Download Laravel


Let us begin the tutorial by installing a new laravel application. if you have already created the project, then skip following step.

composer create-project laravel/laravel example-app

Install simplesoftwareio/simple-qrcode

In the first step, we will install simplesoftwareio/simple-qrcode Package that provides to generates QR codes in laravel application. So, first, open your terminal and run bellow command:

composer require simplesoftwareio/simple-qrcode

Solution 1: Laravel Generate QR Code Example

Here, we will create a simple route for generating QR code, Then I will show you the output bellow as well:

routes/web.php

<?php

use Illuminate\Support\Facades\Route;

/*

|--------------------------------------------------------------------------

| Web Routes

|--------------------------------------------------------------------------

|

| Here is where you can register web routes for your application. These

| routes are loaded by the RouteServiceProvider within a group which

| contains the "web" middleware group. Now create something great!

|

*/

Route::get('qrcode', function () {

return QrCode::size(300)->generate('A basic example of QR code!');

});

Output:

Solution 2: Laravel Generate QR Code and Save Example

Here, we will create simple route for generating qr code:

routes/web.php

<?php

use Illuminate\Support\Facades\Route;

/*

|--------------------------------------------------------------------------

| Web Routes

|--------------------------------------------------------------------------

|

| Here is where you can register web routes for your application. These

| routes are loaded by the RouteServiceProvider within a group which

| contains the "web" middleware group. Now create something great!

|

*/

Route::get('qrcode-with-color', function () {

$path = public_path('qrcode/'.time().'.png');

return QrCode::size(300)

->generate('A simple example of QR code', $path);

});

Solution 3: Laravel Generate QR Code with Color Example

Here, we will create a simple route for generating QR code, Then i will show you the output bellow as well:

routes/web.php

<?php

use Illuminate\Support\Facades\Route;

/*

|--------------------------------------------------------------------------

| Web Routes

|--------------------------------------------------------------------------

|

| Here is where you can register web routes for your application. These

| routes are loaded by the RouteServiceProvider within a group which

| contains the "web" middleware group. Now create something great!

|

*/

Route::get('qrcode-with-color', function () {

return QrCode::size(300)

->backgroundColor(255,55,0)

->generate('A simple example of QR code');

});

Output:

Solution 4: Laravel Generate QR Code with Image Example

Here, we will create a simple route for generating QR code, Then I will show you the output bellow as well:

routes/web.php

<?php

use Illuminate\Support\Facades\Route;

/*

|--------------------------------------------------------------------------

| Web Routes

|--------------------------------------------------------------------------

|

| Here is where you can register web routes for your application. These

| routes are loaded by the RouteServiceProvider within a group which

| contains the "web" middleware group. Now create something great!

|

*/

Route::get('qrcode-with-image', function () {

$image = QrCode::format('png')

->merge(public_path('images/1644463030.png'), 0.5, true)

->size(500)

->errorCorrection('H')

->generate('A simple example of QR code!');

return response($image)->header('Content-type','image/png');

});

Output:

Solution 5: Laravel Generate Email QR Code Example

Here, we will create a simple route for generating QR code, Then I will show you the output bellow as well:

routes/web.php

<?php

use Illuminate\Support\Facades\Route;

/*

|--------------------------------------------------------------------------

| Web Routes

|--------------------------------------------------------------------------

|

| Here is where you can register web routes for your application. These

| routes are loaded by the RouteServiceProvider within a group which

| contains the "web" middleware group. Now create something great!

|

*/

Route::get('qrcode-email', function() {

return QrCode::size(500)

->email('hardik@itsolutionstuff.com', 'Welcome to ItSolutionStuff.com!', 'This is !.');

});

Solution 6: Laravel Generate Phone QR Code Example

Here, You can generate qr code with phone number as below:

Code:

QrCode::phoneNumber('111-222-6666');

Solution 7: Laravel Generate SMS QR Code Example

Here, You can generate qr code with sms as below:

Code:

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

Solution 8: Laravel Generate QR Code in Blade File Example

Here, You can generate OR code in blade file:

Code:

<div class="visible-print text-center">

{!! QrCode::size(100)->generate('Demo'); !!}

<p>Scan me to return to the original page.</p>

</div>

I hope it can help you...

#Laravel 9