chillerlan/php-qrcode
Generate and read QR codes in PHP with a modern, namespaced library. Supports Model 2 QR Codes (versions 1–40), ECC levels L/M/Q/H, mixed encoding modes, multiple output formats, and includes a QR Code reader based on ZXing.
storage/app, S3) or direct rendering in views.php.ini or Docker setup. Use Laravel’s config to toggle features dynamically.QRCode::class → Chillerlan\QRCode\QRCode) for dependency injection.dev-main branch is incompatible with released versions. Pin to a stable release (e.g., ^6.0) to avoid breaking changes.Problem or HttpException for consistency.Response::make())?storage/app/qr_codes)?render() method (e.g., <img src="{{ $qrCode->render($data) }}">).Response::make() with Content-Type: image/png.Storage facade to save files (e.g., Storage::put('qr_codes/{hash}.png', $qrCode->render($data, null, 'png'))).Storage::disk('s3')->put().composer require chillerlan/php-qrcode
Add optional dependencies to php.ini or Dockerfile:
extension=gd
extension=imagick
config/app.php:
'providers' => [
Chillerlan\QRCode\ServiceProvider::class,
],
Bind the QRCode class:
$this->app->bind(QRCode::class, function ($app) {
return new QRCode($app['config']['qrcode.options']);
});
config/qrcode.php:
return [
'options' => [
'outputType' => \Chillerlan\QRCode\QROutputInterface::GDIMAGE_PNG,
'version' => 7,
],
];
Facade\QRCode) for cleaner syntax:
use Facade\QRCode as QRCode;
QRCode::render($data)->toFile('path/to/qr.png');
Mockery to stub QRCode for unit tests.FormRequest to validate QR data (e.g., numeric/alphanumeric modes).composer update cautiously.Validator to pre-check input before QR generation.chunk() or queues for bulk operations (e.g., generating 10K QR codes).memory_limit in php.ini.| Failure | Mitigation |
|---|---|
| Missing GD/Imagick | Fallback to SVG output or throw ServiceUnavailableException. |
| Invalid QR Data | Validate input with Laravel’s Validator or QRDataModeInterface::validateString(). |
| Storage Full | Use Laravel’s Storage::fail() to handle disk failures gracefully. |
| High CPU Load | Rate-limit generation (e.g., middleware) or use queues. |
| PHP Version Incompatibility | Pin to a stable release (e.g., ^6.0) and test on Laravel’s supported PHP versions. |
QRCodeService class with Laravel-specific methods (e.g., generateForUser(User $user)).resources/views docs.How can I help you explore Laravel packages today?