Laravel 6 simple qr code generator example tutorial
Today, we will explain to you how to generate QR code in laravel 6. in this example, we use a simple QR code package and you can easily create the QR code with text, color, and image. if you have any unique text, email and phone no then you can create the QR code.
We have provided the steps to install the QR code package for laravel 6. so you can follow the below steps.
Overview
Step 1: Install Laravel
Step 2: Install Package
Step 3: Add providers and aliases
Step 4: Create Route
Step 1: Install Laravel
We are going to install laravel 6, so first open the command prompt or terminal and go to go to xampp htdocs folder directory using the command prompt. after then run the below command.
1 | composer create-project --prefer-dist laravel/laravel larave6_qrcode |
Step 2: Install Package
Now, we are going to install the “simple-qrcode” package using the below command.
1 | composer require simplesoftwareio/simple-qrcode |
Step 3: Add providers and aliases
We will add below providers and aliases in the “config/app.php” file.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | 'providers' => [ .... SimpleSoftwareIO\QrCode\QrCodeServiceProvider::class ], 'aliases' => [ .... 'QrCode' => SimpleSoftwareIO\QrCode\Facades\QrCode::class ] |
Step 4: Create Route
Add the following route code in the “routes/web.php” file. here in this below route file, we already created the QRcode. such as simple, QR code with color and QR code with the image. if you want to display in view file then you can do. so you can see our route file.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | <?php /* |-------------------------------------------------------------------------- | 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(250)->generate('XpertPhp'); }); Route::get('qrcode-with-color', function () { return \QrCode::size(250)->backgroundColor(255,55,0)->generate('XpertPhp'); }); Route::get('qrcode-with-image', function () { return \QrCode::size(250)->format('png')->generate('XpertPhp', public_path('images/qrcode.png')); }); ?> |
Read Also Posts
Laravel 6 Ajax Image Upload example tutorial
Laravel 6 Pagination Example Tutorial
Laravel 6 pdf generator tutorial using dompdf