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

Barcode Laravel Package

milon/barcode

Laravel package for generating 1D/2D barcodes (including QR codes). Create PNG/SVG/HTML outputs or base64 strings, embed in views, and customize size, colors, and formats for labels, invoices, and products.

View on GitHub
Deep Wiki
Context7

Getting Started

Install via Composer: composer require milon/barcode. Publish config with php artisan vendor:publish --provider="Milon\Barcode\BarcodeServiceProvider". The package supports 20+ barcode types (EAN-13, Code 128, QR code, PDF417, etc.) and outputs PNG, SVG, or raw binary. First use case: generate a simple Code 128 barcode for a product SKU and display it inline in a Blade view: {{ DNS2D::getBarcodePNG('SKU-12345', 'C128') }}. The package provides facade aliases (DNS1D, DNS2D) for 1D and 2D barcodes respectively.

Implementation Patterns

Use facades for inline generation in Blade: DNS1D::getBarcodeHTML() or DNS2D::getBarcodeHTML() for SVG output (preferred for scalability). For API responses, return binary PNG data with proper headers: return response(DNS1D::getBarcodePNG('12345', 'C128'))->header('Content-Type', 'image/png'). Batch generation is common for invoices — loop over order IDs, render to temporary files or memory, then merge into PDFs using libraries like DomPDF or TCPDF. Integrate with Eloquent models by defining an accessor: public function getBarcodeAttribute() { return DNS1D::getBarcodePNG($this->sku, 'C128'); }. Always configure default path and format in config/barcode.php to avoid repetition.

Gotchas and Tips

The package depends on ext-gd — ensure it’s installed in production (not optional). PNG output now supports bg_color since v12.1.0, but setting it requires passing a hex color in the 4th parameter of getBarcodePNG() (e.g., DNS1D::getBarcodePNG('...', 'C128', 300, 150, '#ffffff')). SVG generation via getBarcodeHTML() can break if the input string contains special HTML entities — always htmlspecialchars() first or use DNS1D::getBarcodeHTML($safeInput, ...). For quality control, pre-validate barcodes against the expected format (e.g., EAN-13 must be 12 or 13 digits) before rendering. Cache rendered barcodes if used heavily — the generator is CPU-light, but I/O to disk/network adds up. If you hit “Call to undefined function” errors after Laravel 12 upgrade, confirm you’re on v12+ (which added Laravel 12.x compatibility).

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
milesj/emojibase
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