devtical / nova-qrcode-field

A Laravel Nova field to generate QR Code
https://packagist.org/packages/devtical/nova-qrcode-field
MIT License
41 stars 14 forks source link

Preprocess field contents before rendering QR? #9

Closed Synchro closed 3 years ago

Synchro commented 3 years ago

I have a field that contains an identifier string, but not a whole URL. I'd like to be able to generate the full URL on the fly from the field, so if my field contains abc123, I'd like to be able to build it into a URL like https://example.com/qr/abc123. Is there some way to dynamically alter the field value before it gets rendered, via a closure or something?

Kristories commented 3 years ago

Yes, you can use computed field :

Qrcode::make('URL', function () {

    return url($this->string_column);
    // http://localhost.test/goto/{value}

    // or

    return 'https://example.com/qr/' . $this->string_column;
    // https://example.com/qr/{value}

}),
Synchro commented 3 years ago

Perfect, thanks