linkxtr / laravel-qrcode
A clean, modern, and easy-to-use QR code generator for Laravel
Installs: 9
Dependents: 0
Suggesters: 0
Security: 0
Stars: 12
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/linkxtr/laravel-qrcode
Requires
- php: ^8.2
- ext-gd: *
- bacon/bacon-qr-code: ^3.0
- illuminate/contracts: ^11.0|^12.0
- illuminate/support: ^11.0|^12.0
Requires (Dev)
- laravel/pint: ^1.0
- nunomaduro/collision: ^8.0
- orchestra/testbench: ^9.0|^10.0
- pestphp/pest: ^2.0|^3.0|^4.0
- pestphp/pest-plugin-laravel: ^2.0|^3.0|^4.0
- phpstan/phpstan: ^2.0
README
A simple and easy-to-use QR Code generator for Laravel, based on the bacon/bacon-qr-code library.
Note: This is version 2.x.
- Version 2.x is the current stable release, requiring PHP 8.2+ and Laravel 11+.
- Version 1.x is the LTS/Maintenance version. If you need Laravel 10 support or PHP 8.1, please use version 1.x.
- Version 2.x drops compatibility with
simplesoftwareio/simple-qrcodeto provide a more streamlined API. - π Upgrading? Check out the Upgrade Guide.
Requirements
- PHP 8.2 or higher
- Laravel 11.0 or higher
ext-imagickextension (optional, but recommended for better performance). Ifimagickis not available, the package will automatically fallback to usinggdfor PNG and WebP generation.
π¦ Installation
composer require linkxtr/laravel-qrcode
The package uses Laravel's package auto-discovery, so the service provider and facade are registered automatically.
π Quick Start
Basic Usage in Blade Templates
<!-- Display QR code --> {!! QrCode::generate('Hello World!'); !!} <!-- Generate and save to file --> {!! QrCode::generate('Hello World!', public_path('qrcode.svg')); !!}
In Controllers
use Linkxtr\LaravelQrCode\Facades\QrCode; public function generate() { // Return as SVG response return QrCode::generate('QR Code Content'); // Or save to file QrCode::generate('Content', storage_path('app/qrcodes/qr.svg')); // Or get as string $svg = QrCode::generate('Content'); }
β¨ Features
π¨ Enhanced Customization
// Colors and styling QrCode::size(300) ->color(255, 0, 0) ->backgroundColor(255, 255, 255) ->style('dot') ->eye('circle') ->generate('Styled QR Code'); // Error correction QrCode::errorCorrection('H')->generate('Important Data'); // Merge images QrCode::merge('path/to/logo.png')->generate('With Logo');
π± Multiple Data Types
// URLs QrCode::generate('https://example.com'); // Emails QrCode::email('to@example.com', 'Subject', 'Body'); // Phone numbers QrCode::phoneNumber('+1234567890'); // SMS QrCode::SMS('+1234567890', 'Message body'); // WiFi QrCode::wiFi([ 'ssid' => 'Network', 'encryption' => 'WPA', 'password' => 'Password' ]); // Geolocation QrCode::geo(37.7749, -122.4194); // BTC QrCode::btc(['btcaddress', 0.0034, ['label' => 'label', 'message' => 'message', 'returnAddress' => 'https://www.returnaddress.com']]); // vCard QrCode::vCard([ 'name' => 'John Doe', 'first_name' => 'John', 'last_name' => 'Doe', 'email' => 'john@example.com', 'phone' => '+1234567890', 'company' => 'Tech Corp', 'title' => 'Developer', 'url' => 'https://example.com' ]); // Calendar Event QrCode::calendar([ 'summary' => 'Laracon US', 'description' => 'The official Laravel conference.', 'location' => 'New York, NY', 'start' => Carbon::create(2024, 8, 27, 9, 0, 0), 'end' => Carbon::create(2024, 8, 28, 17, 0, 0), ]);
π§ Advanced Usage
All Available Methods
// Size and format QrCode::size(250)->format('png')->generate('Content'); // Colors with RGB QrCode::color(255, 0, 0)->generate('Red QR'); // Background color QrCode::backgroundColor(255, 255, 0)->generate('Yellow background'); // Margin QrCode::margin(2)->generate('With margin'); // Encoding QrCode::encoding('UTF-8')->generate('Unicode content'); // Gradient colors QrCode::gradient(0, 0, 255, 255, 0, 0, 'vertical')->generate('Gradient');
Error Correction Levels
L- 7% of data bytes can be restoredM- 15% of data bytes can be restoredQ- 25% of data bytes can be restoredH- 30% of data bytes can be restored (default)
QrCode::errorCorrection('H')->generate('High error correction');
Image Merging
Image merging is supported for PNG, WebP, and SVG formats.
// Merge with logo QrCode::format('png')->merge('path/to/logo.png', 0.3, true)->generate('With Logo'); // Merge with SVG QrCode::format('svg')->merge('path/to/logo.png', 0.3, true)->generate('With Logo');
Note: Image merge is not supported for EPS format.
π‘ Common Examples
Generate QR for Website
QrCode::size(200) ->generate('https://your-website.com');
QR Code with Logo
QrCode::size(300) ->merge(public_path('logo.png'), 0.3, true) ->generate('QR with logo');
Colorful QR Code
QrCode::size(300) ->color(58, 94, 255) ->backgroundColor(255, 255, 255) ->generate('Colorful QR');
WiFi QR Code
QrCode::wiFi([ 'ssid' => 'MyWiFi', 'encryption' => 'WPA', 'password' => 'my-password' ]);
Styled QR Code
QrCode::size(250) ->color(255, 0, 0) ->style('dot') ->eye('circle') ->margin(1) ->generate('Styled QR Code');
π€ Contributing & πΊοΈ Roadmap
Version 2 Roadmap
We're actively working on Version 2 with these planned features:
- vCard data type
- Calendar event data type
- WebP format support
- Animated QR codes
- Bitcoin payment QR codes
- Extended customization options
Contributing
We welcome contributions! Please see CONTRIBUTING.md for details.
Request Features
Have an idea? Open an issue with your feature request!
π Troubleshooting
Common Issues
QR code not displaying in blade:
<!-- Make sure to use unescaped output --> {!! QrCode::generate('Content') !!} β {{ QrCode::generate('Content') }} β
File permission errors:
// Ensure directory exists and is writable QrCode::generate('Content', storage_path('app/qrcodes/qr.svg'));
Large QR codes:
// For large content, use higher error correction QrCode::size(400) ->errorCorrection('H') ->generate('Very long content...');
π API Reference
Core Methods
generate($text, $filename = null)- Generate QR codesize($size)- Set size in pixelscolor($red, $green, $blue, $alpha = null)- Set QR color (alpha 0-127)backgroundColor($red, $green, $blue, $alpha = null)- Set background color (alpha 0-127)style($style)- Set style (dot, square, round)eye($style)- Set eye style (circle, square)gradient($startRed, $startGreen, $startBlue, $endRed, $endGreen, $endBlue, $type)- Set gradient colorformat($format)- Set format (svg, png, eps, webp)margin($margin)- Set margin sizeerrorCorrection($level)- Set error correction level (L, M, Q, H)encoding($encoding)- Set character encodingmerge($image, $percentage, $absolute)- Merge image/logo
Data Type Methods
email($to, $subject, $body)- Generate email QRphoneNumber($phone)- Generate phone QRSMS($phone, $message)- Generate SMS QRgeo($lat, $lng)- Generate location QRwiFi($config)- Generate WiFi QRbtc($config)- Generate BTC QRvCard($config)- Generate vCard QRcalendar($config)- Generate Calendar Event QR
π License
This package is open-sourced software licensed under the MIT license.
π Acknowledgments
- Based on the original work by
simplesoftwareio/simple-qrcode - Built upon
bacon/bacon-qr-code - Maintained by khaled-sadek and contributors
Need help? Open an issue β’ Found a bug? Report it
β If you find this repository useful, please consider starring it.