How to Generate QR Code in Laravel 10?
Hey Artisan,
This tutorial shows you laravel 10 generate qr code. I’m going to show you about how to generate qr code in laravel 10. if you want to see an example of how to create qr code in laravel 10 then you are in the right place. I explained simply about how to save generated qr code in laravel.
In this example, we will generate a QR code using simplesoftwareio/simple-qrcode composer package. I will give you a very simple example of generating QR code with image, QR code with color, QR code with SMS, QR code with email, and QR code in blade file, etc.
Step for Laravel 10 Generate QR Code Example
- Step 1: Install Laravel 10
- Step 2: Install simplesoftwareio/simple-qrcode
- 1: Laravel Generate QR Code Example
- 2: Laravel Generate QR Code and Save Example
- 3: Laravel Generate QR Code with Color Example
- 4: Laravel Generate QR Code with Image Example
- 5: Laravel Generate Email QR Code Example
- 6: Laravel Generate Phone QR Code Example
- 7: Laravel Generate SMS QR Code Example
- 8: Laravel Generate QR Code in Blade File Example
Let's see the bellow step and you can generate QR code in your laravel 10 projects as well.
Install Laravel 10
This is optional; however, if you have not created the laravel app, then you may go ahead and execute the below command:
composer create-project laravel/laravel example-app
Install simplesoftwareio/simple-qrcode
In first step we will install simplesoftwareio/simple-qrcode Package that provides to generate QR code in laravel application. So, first open your terminal and run bellow command:
composer require simplesoftwareio/simple-qrcode
1: Laravel Generate QR Code Example
Here, we will create simple route for generating qr code, Then i will show you output bellow as well:
routes/web.php
<?php
use Illuminate\Support\Facades\Route;
/*
|--------------------------------------------------------------------------
| 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(300)->generate('A basic example of QR code!');
});
Output:
2: Laravel Generate QR Code and Save Example
Here, we will create simple route for generating qr code:
routes/web.php
<?php
use Illuminate\Support\Facades\Route;
/*
|--------------------------------------------------------------------------
| 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-with-color', function () {
$path = public_path('qrcode/'.time().'.png');
return QrCode::size(300)
->generate('A simple example of QR code', $path);
});
3: Laravel Generate QR Code with Color Example
Here, we will create simple route for generating qr code, Then i will show you output bellow as well:
routes/web.php
<?php
use Illuminate\Support\Facades\Route;
/*
|--------------------------------------------------------------------------
| 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-with-color', function () {
return QrCode::size(300)
->backgroundColor(255,55,0)
->generate('A simple example of QR code');
});
Output:
4: Laravel Generate QR Code with Image Example
Here, we will create simple route for generating qr code, Then i will show you output bellow as well:
routes/web.php
<?php
use Illuminate\Support\Facades\Route;
/*
|--------------------------------------------------------------------------
| 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-with-image', function () {
$image = QrCode::format('png')
->merge(public_path('images/1644463030.png'), 0.5, true)
->size(500)
->errorCorrection('H')
->generate('A simple example of QR code!');
return response($image)->header('Content-type','image/png');
});
Output:
5: Laravel Generate Email QR Code Example
Here, we will create simple route for generating qr code, Then i will show you output bellow as well:
routes/web.php
<?php
use Illuminate\Support\Facades\Route;
/*
|--------------------------------------------------------------------------
| 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-email', function() {
return QrCode::size(500)
->email('hardik@itsolutionstuff.com', 'Welcome to ItSolutionStuff.com!', 'This is !.');
});
6: Laravel Generate Phone QR Code Example
Here, You can generate qr code with phone number as below:
Code:
QrCode::phoneNumber('111-222-6666');
7: Laravel Generate SMS QR Code Example
Here, You can generate qr code with sms as below:
Code:
QrCode::SMS('111-222-6666', 'Body of the message');
8: Laravel Generate QR Code in Blade File Example
Here, You can generate OR code in blade file:
Code:
<div class="visible-print text-center">
{!! QrCode::size(100)->generate('Demo'); !!}
<p>Scan me to return to the original page.</p>
</div>
I hope it can help you...
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- Laravel 10 Pagination Example Tutorial
- Laravel 10 Ajax CRUD Tutorial Example
- How to Generate Barcode in Laravel 10?
- Laravel 10 Get Current Logged in User Data Example
- Laravel 10 Resize Image Before Upload Example
- Laravel 10 Scout Full Text Search Tutorial
- Laravel 10 Clear Cache of Route, View, Config, Event Commands
- Laravel 10 Yajra Datatables Tutorial Example
- Laravel 10 Ajax Image Upload Example
- Laravel 10 Mail | Laravel 10 Send Mail Tutorial
- Laravel 10 Eloquent Mutators and Accessors Example
- Laravel 10 Create Custom Helper Functions Example
- Laravel 10 Import Export Excel and CSV File Tutorial
- Laravel 10 Vue JS Auth Scaffolding with Vite Tutorial