How To Generate QRcode In Laravel

Today we will see how to generate QR Code In laravel. Now a day many websites and mobile applications are provide features like login with qrcode, scan qrcode and get more information about products and websites etc using QR Code. In this article we will learn how to create QR Code in Laravel.

So, Here I will show you QRcode example In laravel in my project to give you demo, there are many packeges availalbe in laravel to generate qrcode. here, in this example I will use Endroid QR Code Generator package.

Let's start with code and see how to implement qrcode in laravel.

 Step 1 : Install Application for QRcode Example In Laravel

Type the following command in terminal for create new project in your system.

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


Step 2 : Install Endroid QRcode Package In Your Application

Now, we need to install Endroid QRcode Package for dynamic qrcode generator

composer require endroid/qr-code



Step 3 : Create Controller

Now create controller on this path app\Http\Controllers\QRController.php and add below command.


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(150, 200);
		$qrCode->setWriterOptions(['exclude_xml_declaration' => true]);
		header('Content-Type: '.$qrCode->getContentType());

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


Step 4 : Add Route

We need to add route for generating QR code and view file.


use Illuminate\Support\Facades\Route;



Step 5 :  Create Blade File

And after that we need to create blade file for view / generate and download QRcode. So, add below code in your index.blade.php file

<!DOCTYPE html>
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<title>How To Generate QRcode In Laravel- 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>Click on button to generate Qrcode - 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 QRcode as per your requirments like changes in background and foreground color, QRcode size, QRcode margin etc...



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.