Skip to content

The Builder

RaastQr::make() returns a QrBuilder. Every method returns the builder, so calls chain freely, and nothing is computed until you ask for output.

Full Example

php
use RealRashid\RaastQr\Facades\RaastQr;

$qr = RaastQr::make()
    ->iban('PK33ABCD0000000000000000')
    ->amount('2500.50')
    ->expiry(now()->addDays(3))
    ->size(600)
    ->margin(4)
    ->color('#01411C')
    ->background('#FFFFFF')
    ->errorCorrection('H')
    ->logo(public_path('logo.png'), size: 120)
    ->label('Order #1042')
    ->format('svg');

Payment Methods

MethodDescription
iban(string $iban)The destination Pakistani IBAN. Spaces and casing are normalised.
amount(string|int|float|null $amount)The amount in PKR. Omit for a static code.
expiry(DateTimeInterface|string|null $expiry)When the code stops being offered.
staticCode()Clear both amount and expiry, producing a static payload.

Appearance Methods

MethodDescription
size(int $size)Image edge length in pixels.
margin(int $margin)Quiet zone in modules. Four is the minimum.
color(string|array $color)Colour of the dark modules.
background(string|array $color)Colour behind the modules.
errorCorrection(string $level)L, M, Q or H.
logo(string $path, ?int $size, bool $punchout)Stamp a logo in the centre.
label(string $text, int $size, ?string $font)Print a caption underneath.
format(string $format)png or svg, used by render() and HTTP responses.
option(string $key, mixed $value)Set any renderer option directly.
options(array $options)Merge a bag of renderer options.

Output Methods

MethodReturns
toPayload()The raw Raast payload string.
toPng()Raw PNG bytes.
toSvg()An SVG document string.
toDataUrl()A data: URL for an <img src>.
render()Whichever format is currently selected.
save(string $path)Writes to a local path, returns the path.
store(string $path, ?string $disk)Writes to a filesystem disk.
toResponse($request)An HTTP response with the right content type.
download(?string $filename)An HTTP response with a download disposition.
normalizedIban()The IBAN as the payload will encode it.

Conditionals

The builder uses Laravel's Conditionable trait, so when() and unless() work as they do on a query builder:

php
RaastQr::make()
    ->amount($order->total)
    ->when($order->isRush(), fn ($qr) => $qr->expiry(now()->addHour()))
    ->unless($tenant->hasLogo(), fn ($qr) => $qr->color('#01411C'))
    ->toPng();

Macros

The builder is Macroable, so you can teach it your own house style once and reuse it everywhere. Register macros in a service provider:

php
use RealRashid\RaastQr\QrBuilder;

QrBuilder::macro('branded', function () {
    return $this->color('#01411C')
        ->background('#FFFFFF')
        ->logo(public_path('brand/mark.png'), 120)
        ->errorCorrection('H');
});
php
RaastQr::make()->amount('2500')->branded()->toPng();

Echoing in Blade

The builder implements __toString(). In png format it renders a data URL; in svg format it renders the SVG markup:

blade
<img src="{{ RaastQr::make()->amount($order->total) }}" alt="Scan to pay">

Made with ❤️ from Pakistan