Hi All,
Today,I will going to learn you how create QR Code using laravel 8. I will show QR Code generator example in laravel 8. We will simple use a composer package to generate QR code. Using simplesoftwareio/simple-qrcode package in laravel 8 we can easily generate QR code.
Using this simplesoftwareio/simple-qrcode package, you can generate simple qr code, qr code, image qr code, text qr code in laravel 8 app. As well as, you can send this qr codes in mail and text message.
In this tutorial, i will use simplesoftwareio/simple-qrcode package to generate qrcode and will save that qrcode into laravel application.
Step 1 : Install Laravel 8 Application using composer
We need to install laravel 8 application to our system.
composer create-project --prefer-dist laravel/laravel blog
Step 2 : Install QR code generation package via composer
Now In this step, install simplesoftwareio/simple-qrcode package in laravel 8 app via following command.
composer require simplesoftwareio/simple-qrcode
Step 3 : Configure QR code Generator Package
Now just go to config/app.php and configure that for use
'providers' => [ .... SimpleSoftwareIO\QrCode\QrCodeServiceProvider::class ],
'aliases' => [ .... 'QrCode' => SimpleSoftwareIO\QrCode\Facades\QrCode::class ]
Step 4 : Create Controller
Lets create a controller and make function inside it.
php artisan make:controller QrCodeGeneratorController
namespace App\Http\Controllers; use Illuminate\Http\Request; class QrCodeGeneratorController extends Controller { public function index() { return view('qrCode'); } }
Step 5 : Create a link where you want to display
Lets create a controller and make function inside it.
use App\Http\Controllers\QrCodeGeneratorController;
Route::get('/qr-code', [QrCodeGeneratorController::class, 'index']);
Step 6 : Create a view file
Lets create a view file inside resources/views/qrCode.blade.php
use App\Http\Controllers\QrCodeGeneratorController;
And in the blade file just use this line inside body section.
{!! QrCode::size(250)->generate('learning-points.in') !!}
Step 7 : Run the application
php artisan serve
Step 8 : Go to created url
http://127.0.0.1:8000/qr-code
Hope it will help you. Thanks.
I will recommend you to please see the above video for more QR code related configuration and features:
1. How to generate dynamic QR Code.
2. How to set encoding format.
3. How to save generated QR code into your storage folder.
4. How to style your QR code.
5. How to decide image format
and some more things..