---
title: "Custom payloads — QR for Laravel | Roundly"
description: "Implement the Payload contract for your own content — tickets, labels — with its own requirements and sensitivity."
url: https://roundly-consulting.com/open-source/docs/qr-for-laravel/custom-payloads
language: en
---

[All packages](https://roundly-consulting.com/open-source.md)

[QR for Laravel](https://roundly-consulting.com/open-source/docs/qr-for-laravel.md)

# Custom payloads

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

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

```php
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](https://roundly-consulting.com/support-us.md)

By donating, you agree to our [donation terms](https://roundly-consulting.com/donation-terms.md).

[Support our open source work (opens in a new tab)](https://donate.stripe.com/dRmeVe8FX5PF1Qd9pXcEw00) [Join us on Patreon (opens in a new tab)](https://www.patreon.com/cw/roundly)

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

[Get a quote in 48 hours](https://roundly-consulting.com/contact.md) [Browse all packages](https://roundly-consulting.com/open-source/docs/qr-for-laravel.md)
