Laravel 10 QR Code Generator Tutorial Example

Laravel 10 QR Code Generator Tutorial Example

If you need to create a project in Laravel 10 Web Application to generate the code. So for this, you can use simplesoftwareio/simple-qrcode with Laravel 10 . Using this package, you can change the text, size, color, background color, format like png, eps, SVG of your qr codes. And also using this package you can send QR code to mail or mobile also.

In this tutorial, you will learn how to create or generate different types of QR codes in Laravel 10 app using simple-QRcode or simplesoftwareio/simple-qrcode.

Laravel 10 QR Code Generator Tutorial Example

By using the following steps, you can generate various types of QR codes in Laravel 10 apps:

  • Step 1 – Create New Laravel 10 App
  • Step 2 – Setup Database with Laravel App
  • Step 3 – Install simple-QRcode Package
  • Step 4 – Setup Simple QR Code Package
  • Step 5 – Add Routes for Different Types of Qr Code
  • Step 6 – Run Development Server

Step 1 – Create New Laravel 10 App

First of all, start your terminal to download or install Laravel 10 new setup. Run the following commands in it to install the new Laravel 10 app on your system:

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

Step 2 – Setup Database with Laravel App

In this step, open .env and configure database details for connecting app to database:

 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

Step 3 – Install simple-QRcode Package

In this step, Execute the following command terminal to install simple-QRcode package for generate different types of QR code generators in Laravel 10 app:

composer require simplesoftwareio/simple-qrcode

Step 4 – Setup Simple QR Code Package

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

 //config/app.php

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

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

Step 5 – Add Routes for Different Types of Qr Code

Now, open web.php file and add the following routes into it, which is located inside routes directory:

Simple Qr code :

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 you hit the route /QRcode, you get the QR code as below :

php qr code
QR Code with Color :

Now, you 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 :

Now, 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 :

You can use the following routes to send qr code in email:

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

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

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

Step 6 – Run Development Server

Now, execute the following command on terminal to start development server:

php artisan serve

Conclusion

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

Recommended Laravel Posts

AuthorAdmin

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.

Leave a Reply

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