Hello Laravel Friends,
In today’s blog file, I will explain How to Generate a QR Code in Laravel 9.
QR code can be a valuable addition to your Laravel project. Assigning a QR code to each product helps to efficiently manage inventory and simplify the tracking process.
Creating a QR code in Laravel 9 can be achieved using a package called “Simple-QR-Code.” This package provides a simple and straightforward way to generate QR codes for various content types. Here, I’ll guide you through the process step by step.
Steps to Generate QR Code in Laravel 9:
Step 1: Create a Laravel project using the below command
1 |
composer create-project laravel/laravel:^9.0 your-project-name |
Step 2: Now install the package simplesoftwareio/simple-qrcode to generate the QR code
Use the below command
1 |
composer require simplesoftwareio/simple-qrcode "~4" |
Step 3: Add the below lines in the service provider
1 2 3 |
'providers' => [ SimpleSoftwareIO\QrCode\QrCodeServiceProvider::class ], |
And aliases in config/app.php
1 2 3 |
'aliases' => [ 'QrCode' => SimpleSoftwareIO\QrCode\Facades\QrCode::class ], |
Step 4: Create one route in the web.php file and create one blade file in the view folder to show the QR code
path – routes/web.php
1 2 3 |
Route::get('/', function () { return view('welcome'); }); |
path – resources/views/welcome.blade.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Laravel QR Blog</title> </head> <body class="antialiased"> <div> {!! QrCode::generate('Make me into a QrCode!') !!} </div> </body> </html> |
Now, you can run it in your browser and check it.
Output:
Step 5: You can change the color of the QR code using the below code
1 |
{!! QrCode::size(150)->color(75, 0, 130)->generate('Make me into a QrCode!') !!} |
Output:
Conclusion:
Hence, using the above method, you can easily generate a QR code in your Laravel 9 application and change its color as per your requirement. If you have any doubts about generating the QR code for your Laravel application, let me know through the comment section, or you can connect with experienced Laravel Developers to further customize QR codes for your Laravel project.
Happy Coding!