jeeven / qrcode
A Laravel package for generating QR codes (PNG, SVG, Base64, HTTP response).
Requires
- php: ^8.1
- endroid/qr-code: ^6.0
- illuminate/support: ^10.0|^11.0|^12.0|^13.0
Requires (Dev)
- orchestra/testbench: ^8.0|^9.0|^10.0|^11.0
- phpunit/phpunit: ^10.0|^11.0
README
A modern Laravel package for generating QR codes — PNG, SVG, WebP, Base64 data URIs, and direct HTTP responses. Built on top of endroid/qr-code v6.
Requires PHP 8.1+ and Laravel 10, 11, 12, or 13.
Installation
composer require jeeven/qrcode
Laravel auto-discovers the service provider and QrCode facade — no manual registration needed.
Optionally publish the config file:
php artisan vendor:publish --tag=qrcode-config
Usage
Basic
use Jeeven\QrCode\Facades\QrCodeGenerator; $png = QrCodeGenerator::make('https://example.com')->toPng();
Fluent options
$svg = QrCodeGenerator::make('https://example.com') ->size(400) ->margin(20) ->format('svg') ->errorCorrection('high') ->color('#1a1a1a') ->backgroundColor('#ffffff') ->toSvg();
Base64 data URI (embed directly in HTML <img>)
$dataUri = QrCodeGenerator::make('order-12345')->toBase64(); // <img src="{{ $dataUri }}">
Direct HTTP response (streams the image)
// routes/web.php Route::get('/my-qr', function () { return QrCodeGenerator::make('https://example.com')->format('png')->toResponse(); });
Save to disk
QrCodeGenerator::make('https://example.com')->format('svg')->save(storage_path('app/qr/mycode.svg'));
With a label
QrCodeGenerator::make('https://example.com') ->label('Scan me!', fontSize: 18) ->toPng();
With a logo overlay
QrCodeGenerator::make('https://example.com') ->logo(public_path('images/logo.png'), size: 60) ->toPng();
Built-in HTTP endpoint
The package registers GET /qrcode/{data} (configurable prefix) when qrcode.route.enabled is true in config.
GET /qrcode/https://example.com?size=300&format=png&color=%23000000
Query params: size, margin, format, error_correction, color, background_color.
Disable this route entirely by setting route.enabled to false in config/qrcode.php, or by publishing the config and adjusting it per environment.
Configuration reference (config/qrcode.php)
| Key | Default | Description |
|---|---|---|
size |
300 |
QR code width/height in pixels |
margin |
10 |
Quiet-zone margin in pixels |
format |
png |
png, svg, webp, or eps |
error_correction |
high |
low, medium, quartile, high |
color |
#000000 |
Foreground hex color |
background_color |
#ffffff |
Background hex color |
route.enabled |
true |
Toggle the built-in HTTP endpoint |
route.prefix |
qrcode |
URL prefix for the endpoint |
route.middleware |
['web'] |
Middleware applied to the route |
API
Jeeven\QrCode\QrCodeGenerator (accessible via the QrCode facade or DI):
| Method | Description |
|---|---|
make(string $data) |
Start a new QR code (static) |
data(string $data) |
Set/override the data |
size(int $size) |
Set pixel size |
margin(int $margin) |
Set margin |
format(string $format) |
png|svg|webp|eps |
errorCorrection(string $level) |
low|medium|quartile|high |
color(string $hex) |
Foreground color |
backgroundColor(string $hex) |
Background color |
label(string $text, int $fontSize = 16) |
Add caption text below the code |
logo(string $path, ?int $size = 60) |
Overlay a logo image |
generate() |
Returns raw endroidResultInterface |
toString() |
Raw string/binary output |
toPng() / toSvg() / toWebp() |
Format-specific string output |
toBase64() |
Base64 data URI |
save(string $path) |
Write to disk |
toResponse() |
Symfony/Laravel HTTPResponse |
Testing
composer test
License
MIT