How To Create QR Code Generator In Laravel 9

In this article, we will see how to create QR code generator in laravel 9. As per the current trend, many websites and applications provide features like login with QR code, scan QR code, and get more information about products and websites, etc. we will generate dynamic QR codes in laravel 9. There are many packages available to generate QR codes. we will use Endroid QR Code Generator to create QR Code.

So, let's see how to generate QR code in laravel 9, laravel 9 QR code generator.

Step 1: Install Laravel 9 for QR Code

Step 2: Install Endroid QR Code Package

Step 3: Create Controller

Step 4: Add Route

Step 5:  Create Blade File


Step 1: Install Laravel 9 For QR Code

In this step, we will install the laravel 9 application using the following command.

composer create-project --prefer-dist laravel/laravel Laravel_9_QRCode_Generator



Step 2: Install Endroid QR Code Package

In this step, we will install the Endroid QR Code package using the following command.

composer require endroid/qr-code


Step 3: Create Controller

Now, we will create a QRController.php file.



namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Endroid\QrCode\QrCode;
use Endroid\QrCode\ErrorCorrectionLevel;
use Endroid\QrCode\LabelAlignment;

class QRController extends Controller
    public function index()
    	return view('qrcode.index');
    public function create()
		$qrCode = new QrCode('');
		$qrCode->setForegroundColor(['r' => 0, 'g' => 0, 'b' => 0, 'a' => 0]);
		$qrCode->setBackgroundColor(['r' => 255, 'g' => 255, 'b' => 255, 'a' => 0]);
		$qrCode->setLogoSize(200, 200);
		$qrCode->setWriterOptions(['exclude_xml_declaration' => true]);
		header('Content-Type: '.$qrCode->getContentType());

		return redirect()->route('qrcode.index');



Step 4: Add Route

In this step, we will add routes in the web.php file.



use Illuminate\Support\Facades\Route;
use App\Http\Controllers\QRController;
| 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('/', function () {
    return view('welcome');



Step 5: Create Blade File

Now, we will create a blade file for viewing.


<!DOCTYPE html>
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<title>How To Create QR Code Generator In Laravel 9 - Techsolutionstuff</title>
		<link rel="stylesheet" href="">
		<form class="text-center" action="{{route('qrcode.create')}}" method="get" accept-charset="utf-8">
			<div class="row mt-5">
				<div class="col-md-12">
					<h2>How To Create QR Code Generator In Laravel 9 - Techsolutionstuff</h2>
					<button class="btn btn-success" type="submit">Generate</button> 
					<a href="{{asset('qrcode.png')}}" class="btn btn-primary" download>Download</a><br>
					<img class="img-thumbnail" src="{{asset('qrcode.png')}}" width="150" height="150" style="margin-top: 20px">

You can customize this QR code as per your requirements like background colors, foreground color, QR code size, QR code margin, etc...

To check this example run the below code in your browser.



You might also like:


Techsolutionstuff | The Complete Guide

I'm a software engineer and the founder of Hailing from India, I craft articles, tutorials, tricks, and tips to aid developers. Explore Laravel, PHP, MySQL, jQuery, Bootstrap, Node.js, Vue.js, and AngularJS in our tech stack.