1. Go to this page and download the library: Download bitdreamit/laravel-qz-tray library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
bitdreamit / laravel-qz-tray example snippets
return [
// Paths where the auto-generated certificate and key are stored
'cert_path' => storage_path('qz/digital-certificate.txt'),
'key_path' => storage_path('qz/private-key.pem'),
'cert_ttl' => 3600, // seconds the browser may cache the cert
// Certificate generation settings
'certificate' => [
'validity_days' => 7300, // ~20 years
'algorithm' => 'sha256',
'key_bits' => 2048,
'subject' => [
'countryName' => 'US',
'organizationName' => 'My Company',
'commonName' => 'My App QZ Tray',
'emailAddress' => '[email protected]',
],
],
// Auto-generate on first boot (safe for development, use artisan in production)
'auto_generate_cert' => env('QZ_AUTO_GENERATE_CERT', false),
// Allow HTTP endpoint to generate cert (disabled by default — security risk)
'allow_public_cert_generate' => env('QZ_ALLOW_PUBLIC_CERT_GENERATE', false),
// Default printer name (optional — users can pick via modal)
'default_printer' => env('QZ_DEFAULT_PRINTER'),
'allow_printer_switch' => true,
'remember_printer_per_page' => true, // Remember per URL path
'printer_cache_duration' => 86400, // seconds (24 hours)
// v1.1.0+: which identity wins when a request matches more than one
// (device UUID, authenticated user, session)? 'device' first is correct
// for shared/kiosk workstations where the physical machine — not who's
// logged in — determines the printer. Use ['user', 'device', 'session']
// if printer choice should follow a person between machines instead.
'identity_priority' => ['device', 'user', 'session'],
// v1.1.1+: primary key type for qz_print_jobs. Read at migration time —
// set BEFORE first `php artisan migrate`. 'uuid' (default): id is a
// uuid, safe to hand straight to the client (used as-is by
// GET /qz/jobs and DELETE /qz/jobs/{id}). 'bigint': plain
// auto-increment id.
'id_type' => env('QZ_JOB_ID_TYPE', 'uuid'),
// v1.1.3+: 'v7' (default) — time-ordered uuid, much better DB index
// locality than v4 for a write-heavy table (v4 scatters inserts
// randomly across the B-tree; v7's leading timestamp keeps them
// appending near the end). Falls back to v4 automatically on Laravel
// 10.x (no native Str::uuid7()) or if generation fails for any reason.
'uuid_version' => env('QZ_UUID_VERSION', 'v7'),
// QZ Tray WebSocket connection
'websocket' => [
'host' => env('QZ_WEBSOCKET_HOST', 'localhost'),
'port' => env('QZ_WEBSOCKET_PORT', 8181), // QZ Tray default
'retries' => 1,
'timeout' => 10,
],
// Browser fallback when QZ Tray is not running
'fallback' => [
'enabled' => true, // Open browser print dialog as fallback
'open_in_new_tab' => true,
'show_warning' => true,
],
// Keyboard shortcut to open printer selector
'hotkey' => [
'enabled' => true,
'combination' => 'ctrl+shift+p',
],
// Route configuration
'routes' => [
'prefix' => 'qz', // All routes: /qz/...
'middleware' => ['web'], // Add 'auth' here to protect routes
'throttle' => '60,1',
],
// Print job logging
'logging' => [
'enabled' => env('QZ_LOGGING_ENABLED', false),
'channel' => env('QZ_LOGGING_CHANNEL', 'stack'),
'level' => env('QZ_LOGGING_LEVEL', 'info'),
],
];
// POST /qz/print, POST /qz/printer — either param name works, same column.
// Must match config('qz-tray.id_type') — a bigint value on a uuid-configured
// install (or vice versa) fails validation.
[
'tenant_id' => '482', // id_type = 'bigint'
'project_id' => 'b2b1f6c0-3b3d-4c9a-9e2e-1a2b3c4d5e6f', // id_type = 'uuid'
]
// config/qz-tray.php
'tenant_id_resolver' => fn ($request) => auth()->user()?->tenant_id,
// or for a package like stancl/tenancy:
'tenant_id_resolver' => fn ($request) => tenant('id'),