How to Build a QR Code Generator System With Metadata, Logo & Short Alias (PHP + Laravel).

Building a Complete QR Code Generator System in Laravel

QR codes are everywhere—from product packaging to digital business cards. But most tutorials only teach you how to generate a basic QR code. In real-world applications, you need a system that can store metadata, add branding, track scans, and manage multiple QR types efficiently.

Complete QR Code Generator System in Laravel by Deepak Dubey (ddubeyio)

In this guide, you'll learn how to build a production-ready QR code system in Laravel. We'll cover everything from generating QR codes with logos to tracking scans and managing a dashboard for all your QR codes.

  • Store QR metadata in a database
  • Add your brand logo or watermark
  • Generate short, memorable alias URLs
  • Track how many times each QR code is scanned
  • Manage different types of QR codes (URLs, contacts, PDFs, etc.)

By the end, you'll have a system that's not just functional but also scalable and ready for real-world use.

  • QR Codes
  • Laravel
  • Generator System

1. Features We Will Build

Here's what your QR generator system will include:

Generate Multiple QR Types

Your system will support a variety of QR code types, each serving a different purpose:

  • URL QR: Redirect users to a specific webpage.
  • Contact QR: Share contact details (name, email, phone, etc.)
  • Email QR: Open a pre-filled email draft.
  • Phone QR: Initiate a phone call to a specified number.
  • PDF QR: Link directly to a PDF file for download.
  • Product QR: Display product information or specifications.
  • vCard QR: Share a digital business card.

Store Metadata in Database

Every QR code you generate will be stored in a database with the following details:

  • type: The type of QR code (e.g., contact, url, pdf).
  • data_json: A JSON object containing all the information encoded in the QR code.
  • alias: A short, unique code (e.g., abc123) for easy reference.
  • file_path: The path to the generated QR code image.
  • created_by: The ID of the user who created the QR code.
  • scan_count: The number of times the QR code has been scanned.

Add Logo or Watermark

You can overlay your brand logo or watermark on the QR code, typically in the center. This not only adds a professional touch but also makes your QR codes instantly recognizable.

Generate Short Alias URLs

Instead of long, complex URLs, your system will generate short, easy-to-remember aliases like:

https://yourdomain.com/q/abc12

These short URLs will redirect users to the original target, whether it's a URL, PDF, or contact page.

Dashboard to Manage All QR Codes

You'll build an admin dashboard where you can:

  • View all generated QR codes.
  • Download QR code images.
  • Analyze scan data and performance.
  • Delete or update QR codes as needed.

2. Database Structure

To store all QR-related data, create a table named qr_codes with the following schema:

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
);

This table will store all the metadata for your QR codes, making it easy to retrieve and manage them later.

3. Install Required Packages in Laravel

Install QR Code Generation Package

Use the simplesoftwareio/simple-qrcode package to generate QR codes in Laravel:

composer require simplesoftwareio/simple-qrcode

Install Intervention Image for Logo Processing

The intervention/image package will help you add logos to your QR codes:

composer require intervention/image

Configuration for Laravel < 9

If you're using Laravel 8 or earlier, you'll need to manually register the Service Provider and Facade in config/app.php:

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 random alias for each QR code. This function will generate a unique 6-character code:

function generateAlias($length = 6)
{
    $characters = 'abcdefghijklmnopqrstuvwxyz0123456789';
    return substr(str_shuffle($characters), 0, $length);
}

Place this function in a helper file (e.g., app/helpers.php) and autoload it via composer.json.

5. Generate QR Code With Logo

Here's an example controller method that generates a QR code, adds a logo, and stores the metadata 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 method:

  1. Generates a QR code from the provided data.
  2. Overlays your logo in the center of the QR code.
  3. Saves the final QR code image to the public/qrcodes directory.
  4. Stores the QR code metadata in the qr_codes table.

6. Alias Redirection Route

Create a route to handle redirection based on the QR code alias. This route will read the alias, retrieve the QR code data, and redirect the user accordingly:

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 acts as a smart redirect handler, ensuring users are taken to the correct destination based on the QR code type.

7. Creating Different QR Types

Example Contact QR Data

For a contact QR code, you might use the following JSON structure:

{
  "type": "contact",
  "name": "Deepak Dubey",
  "email": "deepak@example.com",
  "phone": "+91 9876543210",
  "company": "TechLabs"
}

Example URL QR Data

For a URL QR code, the JSON would look like this:

{
  "type": "url",
  "url": "https://deepakddubey.blogspot.com"
}

Example PDF QR Data

For a PDF QR code, you'd specify the path to the PDF file:

{
  "type": "pdf",
  "pdf_path": "uploads/documents/brochure.pdf"
}

The type field determines how the system handles the QR code when it's scanned.

8. Dashboard UI Ideas

Your QR system can include a simple admin dashboard with the following features:

QR List

Display all QR codes in a table with columns for:

  • QR image preview
  • Alias
  • Type
  • Created on
  • Scan count
  • Actions (Download, View, Delete)

Create QR Page

A form where users can:

  • Select the QR type from a dropdown.
  • Fill in the relevant fields (e.g., URL, contact details, PDF path).
  • Upload a logo or watermark.
  • Generate the QR code and receive the image and alias.

QR Analytics (Optional)

Track and visualize QR code performance with:

  • Daily scan counts
  • Device and browser information
  • Basic location data
  • Graphs using a library like Chart.js

9. Real-World Use Cases

Businesses

  • Add QR codes to product packaging for easy access to specifications or manuals.
  • Use QR codes in marketing campaigns to track engagement.
  • Generate payment QR codes for quick transactions.
  • Create digital business cards with vCard QR codes.

Startups

  • Provide app download links via QR codes.
  • Simplify event registration with QR code links.
  • Share onboarding or information pages with new users.

Personal Use

  • Create a digital business card with a QR code.
  • Share your portfolio or blog with a QR code.
  • Link to your resume or CV for easy access.

Conclusion

With Laravel, you can build a powerful QR Code Generator System that goes beyond basic functionality. By storing metadata, adding logos, generating short URLs, and tracking scans, your system will be ready for real-world use in businesses, startups, and personal projects.

If you extend this system with user authentication, subscription plans, and advanced analytics, you could even turn it into a full-fledged SaaS product for QR code management.

QR Codes • Laravel • Generator System • Business Solutions • SaaS Product

By: Deepak Dubey (ddubeyio) 

Deepak Dubey

I'm Deepak Dubey, a developer who loves building practical and scalable web solutions. This blog is where I share quick insights, coding tips, and real project experiences in PHP, Laravel, JavaScript, APIs, Python, and more. I created this space to document useful solutions, explore new technologies, and help others facing similar technical challenges. Thanks for visiting — happy learning!

Post a Comment

Feel free to share your thoughts below!
I love hearing from you — your feedback helps me improve!

Previous Post Next Post