qr:generate Artisan command lets you create QR codes directly from the terminal. It is ideal for build scripts, batch export pipelines, CI/CD workflows, and quick local tests — no PHP code required. The command supports two modes: interactive (guided prompts) and non-interactive (inline flags for scripting).
Interactive mode
Run the command with no arguments to start a guided session. Laravel Prompts walks you through each option — payload, output path, format, and advanced settings — with sensible defaults at every step:- Payload — what to encode (e.g. a URL or plain text)
- Output path — where to save the file (leave blank to print to the console)
- Format —
svg,png,webp, oreps(shown only when an output path is provided) - Advanced options — confirm whether to configure size, colors, margin, and error correction
If you have already passed any advanced flag (e.g.
--size), the
advanced-options prompt defaults to yes so you can fill in the remaining
fields interactively.Non-interactive mode
Pass the payload as a positional argument and use flags to set every option. This mode is designed for scripting — it skips all prompts and exits immediately with a success or failure code.--output, the raw QR code is printed directly to stdout. For SVG this is human-readable markup; for binary formats pipe the output to a file:
All available options
Positional argument. The payload to encode in the QR code. Omit it to
enter interactive mode.
File path to save the generated QR code (e.g.
public/qr.svg,
storage/app/exports/badge.png). If omitted, the output is printed to the
console.Output format:
svg, png, webp, or eps. Unlike the Blade component, the
CLI supports all four formats including EPS for print workflows.Size of the QR code in pixels. Must be a positive integer.
Foreground color as comma-separated RGB or RGBA integers. RGB channels are
0–255; the optional alpha channel is 0–100. Examples: 255,0,0 (red),
0,102,204,80 (blue at 80 % opacity).Background color in the same
R,G,B or R,G,B,A format as --color.Error correction level:
L (7 %), M (15 %), Q (25 %), or H (30 %). Use
H when overlaying a logo to ensure the QR code remains scannable.Quiet-zone margin around the QR code. Must be zero or a positive integer.
Step-by-step: batch export
Use the command in a shell loop to generate QR codes for a list of URLs in one go:Use cases
Build scripts
Generate static QR code assets during your deployment pipeline so they are
always up to date without runtime generation overhead.
Batch export
Loop over a dataset and generate one QR code per record — product codes,
event tickets, asset tags — without writing a custom Artisan command.
CI/CD pipelines
Validate that QR generation works in your environment after every deploy by
running a quick smoke test command in your pipeline.
Local testing
Preview QR code output for any format or option combination instantly,
without spinning up a browser or writing throwaway PHP.
Exit codes
| Code | Meaning |
|---|---|
0 | QR code generated successfully |
1 | Validation error (invalid size, color format, error correction level) or file write failure |
$? immediately after the command to detect and handle failures:
Naming conventions
config/qrcode.php key | CLI flag |
|---|---|
error_correction | --errorCorrection / -E |
background_color | --backgroundColor / -B |
format | --format / -F |
size | --size / -S |
margin | --margin / -M |
color | --color / -C |