generate() method is the terminal call that renders a QR code from whatever payload and styling you have configured on the builder. Every fluent method (size(), color(), style(), and so on) returns a cloned Generator instance, leaving the original untouched, so you can safely reuse a partially-configured base and override individual settings per call.
generate()
$text and, if you supply a $filename, write the output to that path on disk. The method always returns a QrCodeResult regardless of whether a file was written.
Parameters
string
required
The data payload to encode — a URL, plain string, or the pre-formatted output
from any data-type method.
string | null
Absolute or app-relative path where the QR code should be saved (e.g.
storage_path('app/qrcodes/qr.svg')). The directory must already exist and
be writable; the package will not create it for you. When omitted, the QR
code is generated in memory only.Return value
object
An immutable value object that implements
Stringable, Htmlable, and Responsable.Exceptions
Fluent builder entry points
You do not need to construct aGenerator manually. The QrCode facade exposes every configuration method as a static entry point. Each call returns a cloned Generator so the facade’s default state is never mutated.
int
Set the width and height of the QR code in pixels. Returns a cloned
Generator.string
Set the output format before calling
generate(). Accepted values: svg, png, webp, eps. Returns a cloned Generator.int
Set the quiet-zone (whitespace) margin around the QR code in pixels. Returns a cloned
Generator.string
Set the Reed–Solomon error correction level. Accepted values:
L (7%), M (15%), Q (25%), H (30%). Returns a cloned Generator.string
Set the character encoding used when encoding the payload. Defaults to
UTF-8. Returns a cloned Generator.Because every fluent method returns a clone, you can safely store a base configuration and derive variations from it without side-effects: