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

Qr Code Laravel Package

endroid/qr-code

Generate QR codes quickly in PHP. Built on BaconQrCode with optional validation, and multiple writers for PNG, WebP, SVG, EPS, or binary output. Includes a fluent Builder plus extras like Twig extensions, routes, factories, and a Symfony bundle.

View on GitHub
Deep Wiki
Context7

Getting Started

  1. Install via Composer: composer require endroid/qr-code
  2. Ensure GD extension is enabled (php -m | grep gd)—required for PngWriter, WebPWriter, SvgWriter
  3. Generate your first QR code using the fluent Builder:
    use Endroid\QrCode\Builder\Builder;
    use Endroid\QrCode\Writer\PngWriter;
    
    $qr = (new Builder())
        ->writer(new PngWriter())
        ->data('https://your-app.com/ticket/123')
        ->size(200)
        ->build();
    
    $qr->saveToFile(storage_path('app/qrcodes/ticket-123.png'));
    
  4. First real-world use case: dynamically generate QR codes for event tickets, order confirmations, or API keys

Implementation Patterns

  • Use Builder with named config groups: In Laravel, define reusable configurations via a custom service or facade:
    // app/Services/QrCodeService.php
    public function forOrder(Order $order): QrCodeResult
    {
        return (new Builder())
            ->writer(new PngWriter())
            ->data(route('orders.show', $order))
            ->size(300)
            ->margin(10)
            ->logoPath(public_path('img/logo-sm.png'))
            ->logoResizeToWidth(40)
            ->build();
    }
    
  • Write to stream for immediate download: Avoid disk I/O by streaming to response:
    $result = $builder->build();
    return response($result->getString())
        ->header('Content-Type', $result->getMimeType())
        ->header('Content-Disposition', 'inline; filename="ticket-'.$order->id.'.png"');
    
  • Multi-format output: Support both inline (SVG for scalability) and high-res (PNG for print) via content negotiation:
    $writer = $request->wantsJson() 
        ? new SvgWriter() 
        : new PngWriter();
    
  • Leverage queued jobs for bulk generation: For newsletters or shipping labels, dispatch jobs to pre-generate QR codes to S3:
    dispatch(new GenerateShippingLabels($orders->each(fn($o) => $qrService->forOrder($o)->saveToFile($path))));
    

Gotchas and Tips

  • Validation is slow & optional: validateResult(true) triggers a decoder pass—only enable in development or for critical payloads (e.g., payment URLs). Disable in production by default.
  • Logo must be loadable & PNG: Ensure logo paths are absolute (public_path()), and logos are 24-bit PNG with transparency—JPEG logos require manual conversion or will fail silently.
  • SVG writer quirks: SVG output may render tiny if width/height attributes are missing—use WRITER_OPTION_EXCLUDE_WIDTH_AND_HEIGHT => false or add CSS max-width: 100%.
  • Color handling: Hex colors require conversion to RGB: new Color(hexdec(substr($hex, 1, 2)), hexdec(substr($hex, 3, 2)), hexdec(substr($hex, 5, 2))).
  • Error correction trade-offs: ErrorCorrectionLevel::High increases size by ~30% but improves scan reliability on logos/partial occlusion—ideal for product packaging.
  • Debugging readability issues: Inspect $qrCode->getRoundBlockSize()—non-integer values indicate block rounding; set roundBlockSizeMode(RoundBlockSizeMode::Margin) for sharper output.
  • Encoder gotcha: Barcode scanners may misread UTF-8 with ECI headers—switch to Encoding::ISO_8859_1 if targeting legacy scanners and ASCII-only content.
  • Testing tip: Mock Writer and assert $result->getString() length > 0 (QR codes have predictable minimal structure size).
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
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
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