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.
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.
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.
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).
How can I help you explore Laravel packages today?