Laravel 7/6 generate Bar/QR code example. We would love to share with you how to generate (create) Bar/QR code using simple-QRcode in laravel projects. You can simply create (generate) QR codes with text, size, color, background color, format like png, eps, SVG.
Simple QR/Bar code is a composer package to generate QR code in your laravel application. In this example we will show you how you can send SMS and email of generated QR/Bar code, You can also create QR/Bar code for geo, phone number, text message using a simple QRcode package.
Simple Bar/QR codes package is very easy to install and use. Simple QR code package has provided many functions (options) for creating (generating) QR codes. In this example, we will learn how to use this package and generate QR codes.
if you want to know how to generate or create pdf in laravel you can read this => Generate OR Create PDF In Laravel Example
Generate QR/Bar codes in Laravel
Follow the below steps and easily create or generate QR codes in laravel Projects.
- Install Laravel Fresh Setup
- Set database Credentials In .env File
- Install simple-QRcode Package
- Register Package
- Test Qr Code
- Conclusion
1. Install Laravel Fresh Project
We need to install Laravel fresh application setup using below command, Open your command prompt and run the below command :
composer create-project --prefer-dist laravel/laravel Laravel-QR-Code
2. Set database Credentials In .env File
Next step, you have downloaded the fresh new setup of laravel in your system. So set the database credentials in your application. Let’s open your project .env file and set the database credentials here.
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
3. Install simple-QRcode Package
In this step, we will install a simple-QRcode package for the QR code generator, go to terminal and use the below command for install QR code package in laravel based application.
composer require simplesoftwareio/simple-qrcode
4. Register Package
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 ],
5. Test Qr Code
Now we will generate and test qr code in laravel application.
Simple Qr code :
We will 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 we hit the route /QRcode, we get the QR code as below :
QR Code with Color :
Now We 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 :
QR Code with Image :
We will also 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 :
Email QR code :
We can also automatically fill email, subject, and body when scanned.
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
We can prefilled phone number and text messages when scanned the QR code.
QrCode::SMS('111-222-6666', 'Body of the message');
Conclusion
In this laravel simple QR code tutorial – we have successfully installed and configure a simple QR code package in laravel application. We have also learned how to create (generate) simple QR code in laravel application with send SMS text and email to QR code.
Recommended Laravel Tutorial:
- Laravel Tutorial From Scratch | Step By Step
- Laravel 7, 6 Ajax CRUD(DataTables Js) Tutorial Example
- Laravel 7, 6 – Ajax CRUD (Operation) Application Example
- Laravel 7, 6 Angular JS CRUD Example Tutorial
- Upload Files/Images to Amazon s3 Cloud Using Laravel 6 Filesystem
- Laravel 7,6 CKEditor with Image Upload
- Ajax Image Upload In Laravel Tutorial Example From Scratch
- Laravel 6,7 Intervention Upload Image Using Ajax – Example
- Laravel Upload Image to Database with Validation
- Send Email Example Laravel
- Simple Generator or Create Qr Code Example Laravel
- Laravel Custom Cron Schedule Example Tutorial
- Laravel 6,7 Github Login Example
- Laravel 7, 6 Currency Exchange Rate Calculator
- Charts Example Laravel Tutorial | Pie Chart
- Laravel: Create Newsletter Example Tutorial
- Laravel 7, 6 Highcharts Example Tutorial