Skip to main content
The 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.
generate() throws CannotWriteFileException if the target directory does not exist or the process lacks write permission. Create the directory first or catch the exception explicitly.

Fluent builder chaining

Every method on the QrCode facade returns a new immutable instance, so you can chain calls freely without mutating global state.
Because the builder is immutable, you can create a “base” generator once and reuse it for different payloads without side effects:

Builder method reference

int
Width and height of the QR code in pixels. The config default is 400.
string
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.
int, int, int, int|null
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.
int, int, int, int|null
Background color. Accepts the same arguments as color().
int
Quiet-zone margin around the QR code. The config default is 4.
string
Error correction level: L (7 %), M (15 %), Q (25 %), or H (30 %). The config default is M.
string
Character encoding for the payload, e.g. UTF-8. The config default is UTF-8.
string
Module (dot) shape: square, dot, or round.
string
Finder-pattern eye style: square, circle, or pointy.
string
Inner eye style for composite eye patterns: square, circle, or pointy.
array, array, string
Gradient fill across the QR code modules. Pass start and end colors as RGB arrays and a direction: vertical or horizontal.
string, float
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.
string, float
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.
void
Switch the color model to CMYK. Use 0–100 integer values for each channel.
void
Switch the color model back to RGB (the default). Use 0–255 integer values per channel.
int, int|null
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

Styled QR code examples

Config-driven defaults

When you resolve the QrCode 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.
Publish the config file to customise the global defaults:
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 a QrCodeResult just like generate().

BTC

Email

WiFi

vCard

Geo

SMS

WhatsApp