The <x-qr-code> component is the simplest way to embed a QR code in a template. It handles SVG injection and accessibility attributes automatically.{{-- Minimal usage — renders a 100px SVG --}}
<x-qr-code data="https://example.com" />
Common options:<x-qr-code
data="https://example.com"
size="300"
format="svg"
color="#1a56db"
background-color="#ffffff"
margin="2"
/>
Generate a PNG embedded as a base64 data URI:<x-qr-code
data="https://example.com"
format="png"
size="400"
/>
When format is svg, the component injects the SVG inline (including an accessible <title> and role="img"). When format is png or webp, it renders an <img> tag with a base64 src attribute — no file needs to be written to disk.
Pass extra HTML attributes directly:Any attributes not recognized as component props are forwarded to the rendered element:<x-qr-code
data="https://example.com"
size="200"
class="rounded shadow"
id="product-qr"
/>
Both <x-qr-code> and <x-qrcode> (no hyphen) are registered. Use whichever naming convention matches your project style.
Use the QrCode facade anywhere PHP runs — controllers, jobs, service classes, or commands.use Linkxtr\QrCode\Facades\QrCode;
// Generate an SVG string (default format)
$svg = QrCode::generate('https://example.com');
generate() returns a QrCodeResult object. The object casts to a string automatically. You can echo it directly or pass it to a response.Return an SVG response from a controller:use Illuminate\Http\Response;
use Linkxtr\QrCode\Facades\QrCode;
public function show(): Response
{
$svg = QrCode::size(300)->generate('https://example.com');
return response((string) $svg, 200)
->header('Content-Type', 'image/svg+xml');
}
Save a PNG to disk:QrCode::format('png')
->size(400)
->generate('https://example.com', storage_path('app/qrcodes/site.png'));
Render inline SVG in a Blade template:{{-- Use {!! !!} to output raw (unescaped) SVG markup --}}
{!! QrCode::size(200)->generate('https://example.com') !!}
Always use {!! ... !!} — not {{ ... }} — when rendering SVG output in Blade. The double-curly syntax HTML-escapes the string, which breaks the SVG tags.
Use php artisan qr:generate to create QR codes from the terminal — useful for build scripts, deployment hooks, or quick ad-hoc exports.Interactive mode — run without arguments and follow the prompts:Non-interactive mode — pass data and flags directly:php artisan qr:generate "https://example.com" --output=public/qr.svg
All available options:php artisan qr:generate "https://example.com" \
--output=public/qr.svg \
--format=svg \
--size=400 \
--color=0,0,0 \
--backgroundColor=255,255,255 \
--errorCorrection=M \
--margin=4
| Flag | Short | Description | Default |
|---|
--output | -O | File path to save the QR code. Omit to print to console. | — |
--format | -F | Output format: svg, png, webp, eps | svg |
--size | -S | Size in pixels | 400 |
--color | -C | Foreground color as R,G,B or R,G,B,A (alpha 0–100) | 0,0,0 |
--backgroundColor | -B | Background color as R,G,B or R,G,B,A | 255,255,255 |
--errorCorrection | -E | Error correction level: L, M, Q, H | M |
--margin | -M | Quiet-zone margin around the QR code | 4 |
CLI flags use camelCase (--errorCorrection, --backgroundColor) while the config file uses snake_case (error_correction, background_color). Keep this in mind when translating config values to shell commands.
Print SVG to the console (no file saved):php artisan qr:generate "https://example.com"
Generate a PNG with a custom color:php artisan qr:generate "https://example.com" \
--output=public/qr.png \
--format=png \
--color=58,94,255