Skip to main content
Installing Laravel QR Code takes about a minute. The package uses Laravel’s package auto-discovery, so you won’t touch config/app.php at all — just require the package and start generating.
1

Require the package

Run the following command from your project root:
composer require linkxtr/laravel-qrcode
Composer resolves the package and its only production dependency, bacon/bacon-qr-code.
2

Confirm auto-discovery (nothing to do)

Laravel automatically registers the service provider and the QrCode facade alias. You don’t need to edit config/app.php.To verify, run:
php artisan about
You should see Linkxtr\QrCode\QrCodeServiceProvider listed under Providers.
If your application has disabled package auto-discovery, add the provider and alias manually in config/app.php:
'providers' => [
    Linkxtr\QrCode\QrCodeServiceProvider::class,
],

'aliases' => [
    'QrCode' => Linkxtr\QrCode\Facades\QrCode::class,
],
3

Publish the config (optional)

If you want to set app-wide defaults — such as a different output format, a custom size, or a brand color — publish the config file:
php artisan vendor:publish --tag=qrcode-config
This creates config/qrcode.php in your project:
config/qrcode.php
<?php

declare(strict_types=1);

return [

    /*
    |--------------------------------------------------------------------------
    | Default Format
    |--------------------------------------------------------------------------
    |
    | Supported: "png", "eps", "svg", "webp"
    | Default: "svg" (no image extension required)
    |
    */
    'format' => env('QR_CODE_FORMAT', 'svg'),

    /*
    |--------------------------------------------------------------------------
    | Default Size
    |--------------------------------------------------------------------------
    |
    | Size of the QR code in pixels. Default: 400.
    |
    */
    'size' => (int) (env('QR_CODE_SIZE') ?? 400),

    /*
    |--------------------------------------------------------------------------
    | Default Margin
    |--------------------------------------------------------------------------
    |
    | Quiet-zone margin around the QR code. Default: 4.
    |
    */
    'margin' => (int) (env('QR_CODE_MARGIN') ?? 4),

    /*
    |--------------------------------------------------------------------------
    | Default Color
    |--------------------------------------------------------------------------
    |
    | Foreground color. Accepted formats:
    |   CSV string  "R,G,B"       e.g. "0,0,0"
    |   CSV string  "R,G,B,A"     e.g. "0,0,0,100"  (alpha 0–100)
    |   Hex string  "#RRGGBB"     e.g. "#000000"
    |
    */
    'color' => env('QR_CODE_COLOR', '0,0,0'),

    /*
    |--------------------------------------------------------------------------
    | Default Background Color
    |--------------------------------------------------------------------------
    |
    | Background color. Accepts the same formats as 'color' above.
    |
    */
    'background_color' => env('QR_CODE_BACKGROUND_COLOR', '255,255,255'),

    /*
    |--------------------------------------------------------------------------
    | Error Correction Level
    |--------------------------------------------------------------------------
    |
    | Supported: 'L' (7%), 'M' (15%), 'Q' (25%), 'H' (30%)
    | Default: 'M'
    |
    */
    'error_correction' => env('QR_CODE_ERROR_CORRECTION', 'M'),

    /*
    |--------------------------------------------------------------------------
    | Encoding
    |--------------------------------------------------------------------------
    |
    | Character encoding used when building the QR payload. Default: 'UTF-8'.
    |
    */
    'encoding' => env('QR_CODE_ENCODING', 'UTF-8'),

    /*
    |--------------------------------------------------------------------------
    | Force GD Backend
    |--------------------------------------------------------------------------
    |
    | Set to true if Imagick is installed but you want to force GD instead
    | (e.g., strict server security policies).
    |
    */
    'force_gd' => env('QR_CODE_FORCE_GD', false),
];

Environment variable overrides

Every key in the config file reads from a corresponding environment variable, so you can change defaults per-environment without touching the published file:
Environment variableConfig keyDefault
QR_CODE_FORMATformatsvg
QR_CODE_SIZEsize400
QR_CODE_MARGINmargin4
QR_CODE_COLORcolor0,0,0
QR_CODE_BACKGROUND_COLORbackground_color255,255,255
QR_CODE_ERROR_CORRECTIONerror_correctionM
QR_CODE_ENCODINGencodingUTF-8
QR_CODE_FORCE_GDforce_gdfalse
Config-driven defaults apply automatically when you use the QrCode facade, the <x-qr-code> Blade component, or resolve Linkxtr\QrCode\Generator from Laravel’s container. They do not apply when you call new Generator() directly without passing a config array.
4

Install ext-imagick for PNG/WebP (optional)

SVG and EPS output require no image extensions. For PNG and WebP, the package needs either ext-imagick or ext-gd.

Imagick (recommended)

Provides higher-quality raster output. Install via your system package manager:
# Ubuntu / Debian
sudo apt-get install php-imagick

# macOS (Homebrew)
brew install imagemagick
pecl install imagick

GD (automatic fallback)

GD ships with most PHP distributions. If ext-imagick is not detected, the package silently falls back to GD for PNG and WebP — no configuration needed.
ext-imagick is required for several raster features:
  • WebP output — GD can produce PNG but not WebP.
  • Non-square module stylesdot and round styles require Imagick.
  • Gradients — multi-color foreground gradients require Imagick.
  • Custom eye colors — per-eye color overrides set with eyeColor() require Imagick.
Using any of these features without Imagick throws a MissingExtensionException. SVG and EPS output are unaffected and support every feature without Imagick.
To force GD even when Imagick is present, set QR_CODE_FORCE_GD=true in your .env file or publish the config and set 'force_gd' => true.

What’s installed

After completing the steps above, your application has:
  • The QrCode facade available globally
  • The <x-qr-code> and <x-qrcode> Blade components registered
  • The php artisan qr:generate Artisan command available
  • An optional config/qrcode.php with app-wide defaults
Continue to the Quickstart to generate your first QR code.