Laravel 8 QR code generate example. In this tutorial, you will learn how to generate (create) QR code using simple-QRcode in laravel 8 app. And as well as learn how to generate QR codes with text, size, color, background color, format like png, eps, SVG.
And this tutorial will guide you on how to generate different types of qr codes in laravel 8 app. And also these qr codes via SMS and email.
Note that, Simple Bar/QR codes package is very easy to install and use in laravel 8 app. Simple QR code package has provided many functions (options) for creating (generating) QR codes.
First of all, open terminal and execute the following command on terminal to install or download Laravel 8 app:
composer create-project --prefer-dist laravel/laravel Laravel-QR-Code
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
In this step, Execute the following command terminal to install simple-QRcode package for generate different types of QR code generator in laravel 8 app:
composer require simplesoftwareio/simple-qrcode
After successfully install a simple QR code package in the laravel app. Next, open config/app.php file and add service provider and aliases.
//config/app.php
'providers' => [
….
SimpleSoftwareIO\QrCode\QrCodeServiceProvider::class
],
'aliases' => [
….
'QrCode' => SimpleSoftwareIO\QrCode\Facades\QrCode::class
],
Now, open web.php file and add the following routes into it, which is located inside routes directory:
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 :
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');
});
#laravel #php #web-development #programming #developer