Complete QR Code Generator System in Laravel
QR codes have become a standard way to share business information: contact details, URLs, PDF files, product info, payment links, and more. But most developers only learn to generate a basic QR code.
In real-world applications, you need something more powerful:
- Store QR metadata
- Add brand logo or watermark
- Generate short alias URLs
- Track scans
- Manage multiple QR types
In this guide, you will learn step by step how to build a complete QR Code system in Laravel with all these features.
- QR Codes
- Laravel
- Generator System
1. Features We Will Build
Your QR generator system will include the following features:
Generate Multiple QR Types
- URL QR
- Contact QR
- Email QR
- Phone QR
- PDF QR
- Product QR
- vCard QR
Store Metadata in Database
Example fields to store in the database:
type(contact, url, pdf etc.)data_json(all QR information as JSON)alias(short code likeabc123)file_path(generated QR PNG path)created_byscan_count(optional)
Add Logo or Watermark
You will overlay your brand logo on the QR code, usually in the center.
Generate Short Alias URLs
Example:
https://yourdomain.com/q/abc12
This short URL will redirect to the original target (URL, PDF, contact page, etc.).
Dashboard to Manage All QR Codes
You can manage, view, download, and analyze all generated QR codes from an admin panel.
2. Database Structure
Create a table named qr_codes to store all QR related data.
CREATE TABLE qr_codes (
id BIGINT AUTO_INCREMENT PRIMARY KEY,
alias VARCHAR(50) UNIQUE,
type VARCHAR(50),
data_json LONGTEXT,
file_path VARCHAR(255),
scan_count INT DEFAULT 0,
created_by BIGINT,
created_at TIMESTAMP NULL,
updated_at TIMESTAMP NULL
);
3. Install Required Packages in Laravel
Install QR Code Generation Package
composer require simplesoftwareio/simple-qrcode
Install Intervention Image for Logo Processing
composer require intervention/image
Configuration for Laravel < 9
If you are using Laravel version lower than 9, register the Service Provider and Facade.
In config/app.php (providers array):
Intervention\Image\ImageServiceProvider::class,
In config/app.php (aliases array):
'Image' => Intervention\Image\Facades\Image::class,
4. Generate Short Alias Automatically
Create a helper function to generate a short alias code.
function generateAlias($length = 6)
{
$characters = 'abcdefghijklmnopqrstuvwxyz0123456789';
return substr(str_shuffle($characters), 0, $length);
}
You can place this function in a helper file like app/helpers.php and load it via composer.json autoload section.
5. Generate QR Code With Logo
Below is an example controller method to generate a QR code, merge a logo, and store information in the database.
use SimpleSoftwareIO\QrCode\Facades\QrCode;
use Intervention\Image\Facades\Image;
use App\Models\QRCode;
use Illuminate\Http\Request;
public function createQR(Request $request)
{
$alias = generateAlias();
$data = $request->all();
$jsonData = json_encode($data);
$qrTempPath = public_path("qrcodes/temp_{$alias}.png");
$qrFinalPath = public_path("qrcodes/{$alias}.png");
$logoPath = public_path('logo.png');
// Step 1: Generate QR
QrCode::format('png')
->size(500)
->generate($jsonData, $qrTempPath);
// Step 2: Add Logo
$qrImage = Image::make($qrTempPath);
$logo = Image::make($logoPath)->resize(100, 100);
$qrImage->insert($logo, 'center');
$qrImage->save($qrFinalPath);
// Step 3: Store in DB
QRCode::create([
'alias' => $alias,
'type' => $request->type,
'data_json' => $jsonData,
'file_path' => "qrcodes/{$alias}.png",
]);
return response()->json([
'status' => 'success',
'qr_url' => url("qrcodes/{$alias}.png"),
'alias' => $alias
]);
}
This function:
- Generates a QR image from JSON data.
- Adds a logo at the center using Intervention Image.
- Saves the final QR image.
- Stores metadata in the
qr_codestable.
6. Alias Redirection Route
Create a route that reads the alias and redirects or displays data based on the QR type.
In routes/web.php:
use App\Models\QRCode;
Route::get('/q/{alias}', function ($alias) {
$qr = QRCode::where('alias', $alias)->firstOrFail();
$data = json_decode($qr->data_json, true);
// Increase scan count
$qr->increment('scan_count');
if ($qr->type == 'url') {
return redirect()->away($data['url']);
}
if ($qr->type == 'contact') {
return view('qr.contact', compact('data'));
}
if ($qr->type == 'pdf') {
return redirect()->away(asset($data['pdf_path']));
}
return 'Invalid QR Type';
});
This route behaves like a smart redirect handler for your short alias URLs.
7. Creating Different QR Types
Example Contact QR Data
{
"type": "contact",
"name": "Deepak Dubey",
"email": "deepak@example.com",
"phone": "+91 9876543210",
"company": "TechLabs"
}
Example URL QR Data
{
"type": "url",
"url": "https://deepakddubey.blogspot.com"
}
Example PDF QR Data
{
"type": "pdf",
"pdf_path": "uploads/documents/brochure.pdf"
}
Based on the type field, your application can decide how to handle the redirect or display page.
8. Dashboard UI Ideas
Your QR system can include a small admin dashboard with the following pages.
QR List
- QR image preview
- Alias
- Type
- Created on
- Scan count
- Actions (Download, View, Delete)
Create QR Page
A form where:
- The user selects QR type from a dropdown.
- Fields change dynamically based on QR type.
- The user can upload a PDF file for PDF QR types.
- The user can upload a logo image.
- On submit, the system generates the QR and returns the image and alias.
QR Analytics (Optional)
- Daily scan count
- Device or browser information
- Basic location information
- Graphs using a chart library like Chart.js
9. Real-World Use Cases
Businesses
- Product packaging QR codes
- Marketing pages and campaign links
- Payment links
- Visiting card QR codes
Startups
- App download QR codes
- Event registration links
- Information or onboarding pages
Personal Use
- Digital business cards
- Portfolio or blog link QR
- Resume or CV QR code
Conclusion
With Laravel, you can build a full-featured QR Code Generator System that goes far beyond basic QR creation. By storing metadata, generating alias URLs, adding logos, and tracking scans, your QR tool becomes a powerful, production-ready solution that businesses and individuals can use every day.
If you extend this system with user authentication, subscription plans, and detailed analytics, you can even convert it into a complete SaaS product for QR code management.
