Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Simple Qrcode Laravel Package

simplesoftwareio/simple-qrcode

Laravel-friendly QR code generator built on BaconQrCode. Create PNG/SVG QR codes with a fluent API—set size, colors, margins, error correction, merge images, and output inline or save to files for apps, tickets, and more.

View on GitHub
Deep Wiki
Context7

Getting Started

Install the package via Composer:

composer require simplesoftwareio/simple-qrcode

In Laravel (≥5.5), service provider and facade auto-discovery are enabled by default. Use the QrCode facade immediately in controllers or Blade views:

use SimpleSoftwareIO\QrCode\Facades\QrCode;

// In a controller or route closure
return QrCode::size(200)->generate('https://example.com');

For Blade: output as raw HTML to render SVG inline:

{!! QrCode::generate('Hello World') !!}

First use case: embed a simple QR code on a product page or ticket — just pass the URL or text to encode.


Implementation Patterns

  • Inline SVG in Views: Default output is SVG, ideal for styling with CSS (e.g., color(), backgroundColor()) or animating.
  • Downloadable Images: Use generate($data, $path) to save PNG/SVG/EGF files (e.g., generate and store ticket QRs in storage/app/qrcodes).
  • Email Embedding: Use embedData() with Mail facade or Mailable to embed QRs inline in emails:
    ->embedData(QrCode::size(150)->generate($token), 'token_qr.png', 'image/png')
    
  • Print-Friendly Watermarks: Use conditional printing classes and Blade:
    <div class="visible-print">
      {!! QrCode::size(80)->generate(request()->url()) !!}
      <small>Scan to return</small>
    </div>
    
  • Dynamic Styling: Chain methods for per-request customization (size, color, style, eyes, gradient, margin, error correction, encoding):
    QrCode::format('png')
          ->size(300)
          ->color(0, 51, 102)
          ->backgroundColor(255, 255, 204)
          ->style('round')
          ->eye('circle')
          ->generate($data, $path);
    

Gotchas and Tips

  • PNG requires imagick: If saving PNGs fails, ensure the PHP imagick extension is installed and enabled.
  • Laravel Blade must use {!! !!}: Avoid escaping ({{ }}) — QR output is an HtmlString and escaping breaks SVG/HTML rendering.
  • Return type changed in v4: generate() returns Illuminate\Support\HtmlString in Laravel, not raw string — important if mocking or testing.
  • Error correction tradeoff: Higher levels (e.g., H) improve robustness but reduce data capacity; use M or L for space-constrained codes.
  • Opacity is alpha (0–127): In color()/backgroundColor(), alpha isn’t 0–255 — it’s 0 (opaque) to 127 (fully transparent). Use 127 for 50% transparency approx.
  • Eye styling only in SVG/PNG: Some eyeColor() or style() options only apply meaningfully in SVG format — PNG may ignore fine-grained styling.
  • Encoding matters: Set encoding('UTF-8') for non-Latin text (e.g., Arabic, emojis); default is ISO-8859-1.
  • No active maintenance warning: Last release was in 2021-02-08. Consider endroid/qr-code for actively maintained alternatives with broader support (though simple-qrcode remains stable for basic use).
  • Testing: Mock QrCode::shouldReceive('generate')->andReturn('<svg>…') in unit tests to avoid QR generation overhead or dependency on GD/Imagick.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport
twbs/bootstrap4
php-http/client-implementation
phpcr/phpcr-implementation
cucumber/gherkin-monorepo
haydenpierce/class-finder
psr/simple-cache-implementation
uri-template/tests