Laravel QrCode is an easy to use wrapper for the popular Laravel framework based on the great work provided by Bacon/BaconQrCode. We created an interface that is familiar and easy to install for Laravel users.
Compatible with Laravel 8 – 13 and PHP 8.0 – 8.5.
Run the following command to install the package via Composer:
composer require tarikmanoar/laravel-qrcode
The service provider and facade are auto-discovered by Laravel. Optionally publish the config file:
php artisan vendor:publish --provider="Manoar\QrCode\QrCodeServiceProvider" --tag=config
The config file config/laravel-qrcode.php defines defaults for format, size, margin, error_correction, and encoding. Override any of them in your .env file:
QRCODE_FORMAT=svg
QRCODE_SIZE=100
QRCODE_MARGIN=0
QRCODE_ERROR_CORRECTION=M
QRCODE_ENCODING=UTF-8
Upgrade from v2 or v3 by changing your composer.json requirement to ~4.
You must install the imagick PHP extension if you plan to use the png image format.
The
generatemethod now returns an instance ofIlluminate\Support\HtmlStringwhen running inside Laravel. See #205 for more information.
All references to the QrCode facade need to be updated to:
use Manoar\QrCode\Facades\QrCode;
Add QrCodes to your print views so customers can return to the original page after printing:
<div class="visible-print text-center">
{!! QrCode::size(100)->generate(Request::url()) !!}
<p>Scan me to return to the original page.</p>
</div>
```html->generate('Embed me into an e-mail!'), 'QrCode.png', 'image/png') !!})
#### Inline Data URI (no file save needed)
```html
<img src="">
All examples assume you have imported the facade:
use Manoar\QrCode\Facades\QrCode;
All methods support chaining. generate() must always be called last.
generate(string $text, string $filename = null)
Generates the QrCode. Returns an Illuminate\Support\HtmlString inside Laravel (safe for {!! !!} output) or a plain string outside Laravel.
// Render SVG directly in a Blade view
{!! QrCode::generate('Make me into a QrCode!') !!}
// Save to file
QrCode::generate('Save this!', storage_path('app/qrcode.svg'));
format(string $format)
Supported formats: svg (default), eps, png.
QrCode::format('png')->generate('Hello!');
QrCode::format('eps')->generate('Hello!');
QrCode::format('svg')->generate('Hello!');
imagickPHP extension is required forpngoutput.
size(int $pixels)
QrCode::size(200)->generate('Hello!');
color(int $red, int $green, int $blue, int $alpha = null)
Change the foreground (module) color of the QrCode. All values are 0–255.
QrCode::color(255, 0, 0)->generate('Red QrCode');
QrCode::color(255, 0, 0, 25)->generate('Red with 25% transparency');
Be careful — some readers struggle with colored QrCodes.
colorHex(string $hex)
Shorthand for color() using a CSS hex string. Supports both #RRGGBB and #RGB notation.
QrCode::colorHex('#FF0000')->generate('Red QrCode');
QrCode::colorHex('#f00')->generate('Also red');
backgroundColor(int $red, int $green, int $blue, int $alpha = null)
QrCode::backgroundColor(255, 255, 0)->generate('Yellow background');
backgroundColorHex(string $hex)
QrCode::backgroundColorHex('#FFFF00')->generate('Yellow background');
eyeColor(int $eyeNumber, int $innerRed, int $innerGreen, int $innerBlue, int $outerRed = 0, int $outerGreen = 0, int $outerBlue = 0)
Change the color of one of the three finder-pattern eyes (0, 1, 2).
QrCode::eyeColor(0, 255, 0, 0, 0, 0, 255)->generate('Custom eye 0');
| Eye Number | Position |
|---|---|
0 |
Top-left |
1 |
Top-right |
2 |
Bottom-left |
eyeColorHex(int $eyeNumber, string $innerHex, string $outerHex = '#000000')
QrCode::eyeColorHex(0, '#FF0000', '#0000FF')->generate('Custom eye 0 via hex');
gradient(int $startRed, int $startGreen, int $startBlue, int $endRed, int $endGreen, int $endBlue, string $type)
Apply a color gradient to the QrCode modules.
QrCode::gradient(0, 0, 255, 0, 255, 0, 'vertical')->generate('Gradient');
Supported gradient types:
| Type | Description |
|---|---|
vertical |
Top to bottom |
horizontal |
Left to right |
diagonal |
Top-left to bottom-right |
inverse_diagonal |
Top-right to bottom-left |
radial |
Center outward |
style(string $style, float $size = 0.5)
Change the appearance of the QrCode modules.
QrCode::style('dot')->generate('Dot style');
QrCode::style('round', 0.4)->generate('Rounded style');
| Style | Description |
|---|---|
square |
Default square modules |
dot |
Circular dots |
round |
Rounded squares |
eye(string $style)
Change the finder-pattern eye style.
QrCode::eye('circle')->generate('Circle eyes');
Supported: square, circle.
margin(int $margin)
QrCode::margin(10)->generate('With margin');
errorCorrection(string $level)
QrCode::errorCorrection('H')->generate('High correction');
| Level | Data Recovery |
|---|---|
L |
~7% |
M |
~15% (default) |
Q |
~25% |
H |
~30% |
Higher correction = larger QrCode, less data capacity.
encoding(string $encoding)
Default: ISO-8859-1. Use UTF-8 for non-Latin characters.
QrCode::encoding('UTF-8')->generate('Special symbols ♠♥!!');
Supported encodings: ISO-8859-1 through ISO-8859-16, SHIFT-JIS, WINDOWS-1250 through WINDOWS-1256, UTF-16BE, UTF-8, ASCII, GBK, EUC-KR.
merge(string $filepath, float $percentage = .2, bool $absolute = false)
Overlay a PNG image (e.g. a logo) on top of the QrCode.
// Relative to app base path
QrCode::format('png')->merge('/images/logo.png')->generate('With logo');
// 30% of QrCode size
QrCode::format('png')->merge('/images/logo.png', .3)->generate('With logo');
// Absolute path
QrCode::format('png')->merge('/absolute/path/logo.png', .3, true)->generate('With logo');
mergeString(string $content, float $percentage = .2)
Same as merge() but accepts raw binary content (useful with the Storage facade).
QrCode::format('png')->mergeString(Storage::get('images/logo.png'))->generate('With logo');
Only PNG is supported for merge. Use
errorCorrection('H')to keep the QrCode scannable.
generateBase64(string $text): string
Returns the QrCode as a base64-encoded string.
$b64 = QrCode::generateBase64('https://example.com');
// → "PHN2ZyB4bWxucz0i..."
generateDataUri(string $text): string
Returns the QrCode as a complete data: URI, ready for use in an <img> tag without saving a file.
// SVG (default)
<img src="">
// PNG
<img src="">
reset(): self
Resets all generator settings to their defaults. Useful when the Generator instance is reused across multiple QrCodes.
$qr = new \Manoar\QrCode\Generator();
$qr->size(300)->colorHex('#FF0000')->generate('First');
$qr->reset()->generate('Back to defaults');
Helpers are magic methods that format the QrCode data string for you. They cause a reader to perform a specific action when scanned.
QrCode::BTC($address, $amount);
// Send 0.334 BTC
QrCode::BTC('1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa', 0.334);
// With optional metadata
QrCode::size(500)->BTC('1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa', 0.0034, [
'label' => 'My Donation',
'message' => 'Thank you!',
'returnAddress' => 'https://www.example.com/callback',
]);
QrCode::email($to, $subject, $body);
QrCode::email('foo@bar.com');
QrCode::email('foo@bar.com', 'Subject here', 'Body here');
QrCode::email(null, 'Just the subject', 'And body');
Opens a map application with the specified coordinates.
QrCode::geo($latitude, $longitude);
QrCode::geo(37.822214, -122.481769);
Dials the specified phone number.
QrCode::phoneNumber($phoneNumber);
QrCode::phoneNumber('555-555-5555');
QrCode::SMS($phoneNumber, $message);
QrCode::SMS('555-555-5555');
QrCode::SMS('555-555-5555', 'Pre-filled body');
Connect to a WiFi network by scanning.
QrCode::wiFi([
'encryption' => 'WPA', // WPA, WEP, or omit for open
'ssid' => 'MyNetwork',
'password' => 'secret',
'hidden' => 'true', // optional
]);
// Open network
QrCode::wiFi(['ssid' => 'OpenNet']);
// WPA network
QrCode::wiFi(['ssid' => 'MyNet', 'encryption' => 'WPA', 'password' => 'pass']);
WiFi scanning is not supported on Apple devices.
Generate a vCard 3.0 contact card that adds a contact to the device address book when scanned.
QrCode::vCard([
'first_name' => 'Jane',
'last_name' => 'Doe',
'phone' => '+1234567890',
'email' => 'jane@example.com',
'company' => 'Acme Corp',
'title' => 'Engineer',
'address' => '123 Main St, Springfield',
'url' => 'https://example.com',
'note' => 'Met at conference',
]);
// Shorthand using full name
QrCode::vCard(['name' => 'John Smith', 'phone' => '+9876543210']);
Supported keys: first_name, last_name, name (splits on first space), phone, email, company, title, address, url, note.
Generate a MeCard contact (simpler format, wide Android/iOS scanner support).
QrCode::meCard([
'first_name' => 'Jane',
'last_name' => 'Doe',
'phone' => '+1234567890',
'email' => 'jane@example.com',
'address' => '123 Main St',
'url' => 'https://example.com',
'birthday' => '19900101', // YYYYMMDD
'note' => 'Hello!',
]);
Supported keys: first_name, last_name, name, phone, email, address, url, birthday, note.
Generate an iCalendar (VCALENDAR/VEVENT) QrCode that adds a calendar event when scanned.
QrCode::calendar([
'summary' => 'Team Meeting',
'start' => '20240601T100000Z', // or ISO 8601 string
'end' => '20240601T110000Z',
'location' => 'Conference Room B',
'description' => 'Weekly sync',
'url' => 'https://meet.example.com/abc',
]);
Required keys: summary, start, end. Optional: location, description, url.
Date formats accepted: iCal (20240101T120000Z) or any string parseable by PHP’s strtotime().
Generate a WhatsApp deep-link QrCode that opens a pre-filled chat when scanned.
QrCode::whatsApp('+1234567890', 'Hello there!');
// Phone only (no pre-filled message)
QrCode::whatsApp('+1234567890');
The phone number is normalised automatically (non-numeric characters removed).
Generate an otpauth:// URI for TOTP/HOTP authenticator apps (Google Authenticator, Authy, etc.).
// TOTP (time-based, default)
QrCode::otp([
'label' => 'user@example.com',
'secret' => 'JBSWY3DPEHPK3PXP', // Base32-encoded secret
'issuer' => 'MyApp',
'digits' => 6, // default
'period' => 30, // seconds, default
'algorithm' => 'SHA1', // SHA1, SHA256, or SHA512
]);
// HOTP (counter-based)
QrCode::otp([
'type' => 'hotp',
'label' => 'user@example.com',
'secret' => 'JBSWY3DPEHPK3PXP',
'issuer' => 'MyApp',
'counter' => 0,
]);
Required keys: label, secret. All other keys are optional.
You can also pass raw-format strings directly to generate():
| Usage | Prefix | Example |
|---|---|---|
| Website URL | http:// |
http://www.example.com |
| Secured URL | https:// |
https://www.example.com |
| E-mail Address | mailto: |
mailto:support@example.com |
| Phone Number | tel: |
tel:555-555-5555 |
| Text (SMS) | sms: |
sms:555-555-5555 |
| SMS with message | sms: |
sms:555-555-5555&body=Hello |
| Geo Address | geo: |
geo:-78.400364,-85.916993 |
| MeCard | MECARD: |
MECARD:N:Doe,John;TEL:555-555-5555;; |
| VCard | BEGIN:VCARD |
See Wikipedia |
| WiFi | WIFI: |
WIFI:T:WPA;S:MyNet;P:password;; |
| OTP | otpauth:// |
otpauth://totp/user%40app.com?secret=ABC |
You may use this package outside of Laravel by instantiating a Generator directly:
use Manoar\QrCode\Generator;
$qr = new Generator();
$qr->size(300)->generate('Hello without Laravel!');
// With all new features
$qr->colorHex('#1a1a2e')
->backgroundColorHex('#ffffff')
->size(400)
->errorCorrection('H')
->generateDataUri('https://example.com');