NewWe open-sourced 50+ Laravel packages
Custom AI apps, agents and automation — Roundly ConsultingRoundly
All packages
QR for Laravel

Errors & translations

Every exception extends the abstract QrException (a RuntimeException) and exposes a stable $reason key and the $field it concerns. Messages are fixed English developer messages without payload values; show end users the translated message instead:

use RoundlyConsulting\Qr\Exceptions\QrException;

try {
    $svg = Qr::wifi($ssid, $password)->svg();
} catch (QrException $e) {
    $e->reason;   // stable key, e.g. 'too_short'
    $e->field;    // e.g. 'password' — never the value

    return back()->withErrors([
        'wifi' => __('qr::qr.errors.'.$e->reason, ['field' => $e->field]),
    ]);
}

Hierarchy and reason keys

QrException (abstract)
├── DataTooLongException            data_too_long, input_too_long
├── InvalidOptionException          version_range, mask, size, margin, radius, attribute, error_correction,
│   │                               locked_by_payload, out_of_bounds, eci, render_as
│   └── InvalidColorException       color
├── InvalidQrConfigException        invalid_config ($field = config key)
├── UnencodableCharacterException   unencodable_character
├── InvalidPayloadException         required, too_long, too_short, invalid_format, out_of_range,
│   │                               unsupported_scheme, mutually_exclusive, unsupported_in_version, unrepresentable
│   ├── InvalidIbanException        iban_format, iban_country, iban_length, iban_checksum
│   ├── InvalidBicException         bic_format, bic_country
│   ├── InvalidCreditorReferenceException  creditor_reference_format, creditor_reference_checksum
│   ├── UnsupportedCurrencyException       currency_not_eur, currency_not_iso, currency_mismatch
│   └── PaymentPayloadTooLongException     payload_too_long
├── BySquareDecodeException         bysquare_base32hex, _header, _length, _lzma, _crc, _fields, _value
│   └── CorruptLzmaStreamException  bysquare_lzma
└── MatrixDecodeException           decode_size, decode_format, decode_version, decode_error_correction, decode_segment

DataTooLongException additionally carries neededBits, capacityBits, minVersion, maxVersion and errorCorrection; InvalidPayloadException carries $payloadType.

Translations

The translation file lives under the qr namespace — publish it with the qr-translations tag to reword or translate:

  • qr::qr.title — the default accessible title (“QR code”).
  • qr::qr.descriptions.{text, url, email, phone, sms, wifi, vcard, geo, otpauth, epc, bysquare} — the default <desc> per payload type; url uses :host.
  • qr::qr.validation.{iban, iban_eea, bic, creditor_reference, fits_in_qr_code} — the rule messages.
  • qr::qr.errors.<reason> — one user-facing message per exception reason key.

Show your open-source love

This package is free and MIT-licensed. If it saves you time, a one-off donation or a Patreon membership keeps it maintained, tested and documented.

More ways to support, including crypto

By donating, you agree to our donation terms.

Want this built into your product?

We integrate our packages into custom Laravel and AI builds. Tell us what you're working on and we'll reply within 48 hours.