QrCode facade is the primary way to generate QR codes in PHP code — controllers, jobs, service classes, and Artisan commands. It exposes a fluent builder so you can chain options before calling generate(), and every call inherits the global defaults you set in config/qrcode.php.
Import the facade
Add the facade import at the top of any file that generates QR codes:Basic generation
generate() accepts a string payload and returns a QrCodeResult object. QrCodeResult implements Stringable, so you can cast it directly to a string to get the raw SVG markup (or binary data for PNG/WebP).
Save to a file
Pass a second argument — an absolute file path — to write the output directly to disk. The directory must already exist and be writable.Fluent builder chaining
Every method on theQrCode facade returns a new immutable instance, so you can chain calls freely without mutating global state.
Builder method reference
Width and height of the QR code in pixels. The config default is
400.Output format:
svg, png, webp, or eps. The config default is svg.
PNG and WebP require ext-imagick or ext-gd. EPS requires no extensions.Foreground color. In RGB mode (default):
color(red, green, blue, alpha?)
where each channel is 0–255 and alpha is 0–100. In CMYK mode: color(cyan, magenta, yellow, black) on a 0–100 scale.Background color. Accepts the same arguments as
color().Quiet-zone margin around the QR code. The config default is
4.Error correction level:
L (7 %), M (15 %), Q (25 %), or H (30 %). The
config default is M.Character encoding for the payload, e.g.
UTF-8. The config default is
UTF-8.Module (dot) shape:
square, dot, or round.Finder-pattern eye style:
square, circle, or pointy.Inner eye style for composite eye patterns:
square, circle, or pointy.Gradient fill across the QR code modules. Pass start and end colors as RGB
arrays and a direction:
vertical or horizontal.Overlay an image (e.g. a logo) at the center. Pass a file path and an optional
size percentage (default
0.2 = 20 %). Supported for SVG, PNG, and WebP —
not EPS.Overlay an image passed as raw binary string content instead of a file path.
Accepts the image content and an optional size percentage (default
0.2 = 20
%). Use this when the image is already loaded into memory rather than stored
on disk.Switch the color model to CMYK. Use
0–100 integer values for each channel.Switch the color model back to RGB (the default). Use
0–255 integer values
per channel.Set a grayscale palette.
0 is black, 100 is white. Optionally pass a
second value for the background gray level.Output formats
Using the facade in Blade templates
QrCodeResult is Stringable and its string value contains raw SVG markup (or binary data). Use the unescaped output directive {!! !!} so Laravel does not HTML-encode the angle brackets:
For Blade templates, prefer the
<x-qr-code> component instead — it handles escaping, accessibility attributes, and PNG/WebP base64 embedding automatically. See Blade Component.Returning a QR code from a controller
- SVG response
- PNG response
- File download
Styled QR code examples
Config-driven defaults
When you resolve theQrCode facade, the package automatically reads config/qrcode.php and uses those values as defaults. Any method you chain overrides only that specific option for the current chain.
Config defaults apply when you use the facade, the Blade component, or resolve
Linkxtr\QrCode\Generator from the service container. If you instantiate new Generator() directly, you get hardcoded package defaults unless you pass the
config array yourself.Built-in data-type helpers
The facade includes helpers for common structured payloads. Each returns aQrCodeResult just like generate().