> ## Documentation Index
> Fetch the complete documentation index at: https://docs.linkx.tr/llms.txt
> Use this file to discover all available pages before exploring further.

# Generate QR Codes via the qr:generate Artisan Command

> Use php artisan qr:generate to create QR codes in build scripts, batch exports, CI pipelines, or quick local tests without writing any PHP.

The `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:

```bash theme={null}
php artisan qr:generate
```

The prompt sequence:

1. **Payload** — what to encode (e.g. a URL or plain text)
2. **Output path** — where to save the file (leave blank to print to the console)
3. **Format** — `svg`, `png`, `webp`, or `eps` (shown only when an output path is provided)
4. **Advanced options** — confirm whether to configure size, colors, margin, and error correction

> [!NOTE]
>
> 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.

![Interactive CLI terminal prompt preview](https://mintcdn.com/laravel-qrcode/e1jio7idcPehW76b/images/usage/cli-interactive-terminal.svg?fit=max\&auto=format\&n=e1jio7idcPehW76b\&q=85\&s=138d94dbf54b2e0a086a154c74ffcaf6)

Interactive Laravel Prompts session in php artisan qr:generate

## 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.

```bash theme={null}
# Save a 500 px SVG to public/
php artisan qr:generate "https://example.com" \
  --output=public/qr.svg \
  --format=svg \
  --size=500

# Save a red PNG
php artisan qr:generate "Hello World" \
  --format=png \
  --output=public/qr.png \
  --color=255,0,0

# High error correction, custom margin, white background
php artisan qr:generate "https://example.com" \
  --output=public/qr.svg \
  --errorCorrection=H \
  --margin=6 \
  --backgroundColor=255,255,255

# Print SVG to the console (no --output flag)
php artisan qr:generate "https://example.com"
```

When you omit `--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:

```bash theme={null}
php artisan qr:generate "https://example.com" --format=png > public/qr.png
```

## All available options

**data** `string`

**Positional argument.** The payload to encode in the QR code. Omit it to
enter interactive mode.

**--output / -O** `string`

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.

**--format / -F** `string` (default: svg)

Output format: `svg`, `png`, `webp`, or `eps`. Unlike the Blade component, the
CLI supports all four formats including EPS for print workflows.

**--size / -S** `int` (default: 400)

Size of the QR code in pixels. Must be a positive integer.

**--color / -C** `string` (default: 0,0,0)

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).

**--backgroundColor / -B** `string` (default: 255,255,255)

Background color in the same `R,G,B` or `R,G,B,A` format as `--color`.

**--errorCorrection / -E** `string` (default: M)

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.

**--margin / -M** `int` (default: 4)

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:

**1. Create a URLs file**

```bash theme={null}
cat > urls.txt <<EOF
https://example.com
https://laravel.com
https://packagist.org
EOF
```

**2. Run the loop**

```bash theme={null}
while IFS= read -r url; do
  slug=$(echo "$url" | sed 's|https\?://||;s|/|_|g')
  php artisan qr:generate "$url" \
    --output="public/qrcodes/${slug}.svg" \
    --format=svg \
    --size=400
done < urls.txt
```

**3. Verify the output**

```bash theme={null}
ls -lh public/qrcodes/
```

## Use cases

> [card] Build scripts
>
> Generate static QR code assets during your deployment pipeline so they are
> always up to date without runtime generation overhead.

> [card] 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.

> [card] CI/CD pipelines
>
> Validate that QR generation works in your environment after every deploy by
> running a quick smoke test command in your pipeline.

> [card] 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 |

Scripts can check `$?` immediately after the command to detect and handle failures:

```bash theme={null}
php artisan qr:generate "https://example.com" --output=public/qr.svg

if [ $? -ne 0 ]; then
  echo "QR code generation failed" >&2
  exit 1
fi
```

## Naming conventions

> [!WARNING]
>
> The CLI flags use **camelCase** (e.g. `--errorCorrection`,
> `--backgroundColor`) while the `config/qrcode.php` keys use **snake\_case**
> (e.g. `error_correction`, `background_color`). When translating your config
> values to CLI flags, remember to convert the case.

| `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` |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.