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

Custom payloads

Any content can become a QR code. Implement RoundlyConsulting\Qr\Contracts\Payload and hand the object to Qr::make():

use Illuminate\Contracts\Translation\Translator;
use RoundlyConsulting\Qr\Contracts\Payload;
use RoundlyConsulting\Qr\DataTransferObjects\PayloadRequirements;
use RoundlyConsulting\Qr\Enums\{ErrorCorrection, Sensitivity};

final readonly class TicketPayload implements Payload
{
    public function __construct(private string $code) {}

    public function toQrString(): string { return 'TICKET:'.$this->code; }
    public function requirements(): PayloadRequirements { return new PayloadRequirements(errorCorrection: ErrorCorrection::Quartile); }
    public function sensitivity(): Sensitivity { return Sensitivity::Personal; }
    public function description(Translator $translator): ?string { return 'Event ticket'; }
}

Qr::make(new TicketPayload('A-17'))->svg();
  • toQrString() — the exact bytes to encode.
  • requirements() — encoding needs the payload imposes (level, maximum version, segmentation, ECI, boost) and which options are locked.
  • sensitivity() — Public, Personal or Secret; drives memoisation, caching and HTTP headers.
  • description() — the accessible <desc> text; never include secrets or personal data.

Payload requirements

new PayloadRequirements(              // returned by Payload::requirements()
    errorCorrection: null, maxVersion: null, segmentation: null, eci: null,
    boostErrorCorrection: null, locked: [PayloadRequirements::ECI],
);                                    // locks(string $option): bool; constants ERROR_CORRECTION, ECI,
                                      // SEGMENTATION, BOOST_ERROR_CORRECTION, SENSITIVITY

Options listed in locked throw InvalidOptionException when a caller overrides them with a different value; maxVersion caps whatever version range the caller requests.

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.