PHPackages                             bitdreamit/laravel-qz-tray - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. bitdreamit/laravel-qz-tray

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

bitdreamit/laravel-qz-tray
==========================

Enterprise silent printing with QZ Tray for Laravel - Zero configuration, automatic certificate, browser caching

v0.1.10(3mo ago)014MITJavaScriptPHP ^8.1

Since Jan 13Pushed 3mo agoCompare

[ Source](https://github.com/bitdreamit/laravel-qz-tray)[ Packagist](https://packagist.org/packages/bitdreamit/laravel-qz-tray)[ RSS](/packages/bitdreamit-laravel-qz-tray/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (5)Versions (12)Used By (0)

📦 Laravel QZ Tray - Complete Package Documentation
==================================================

[](#-laravel-qz-tray---complete-package-documentation)

[![Latest Version](https://camo.githubusercontent.com/7c0fcf058842aedf3ad29f291b87fd2d39e2f94cb0d03278ddaabaa5e9083fcc/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f626974647265616d69742f6c61726176656c2d717a2d747261792e737667)](https://packagist.org/packages/bitdreamit/laravel-qz-tray)[![Total Downloads](https://camo.githubusercontent.com/88c5bfe439e02a00ffd46c0e1ce0275791ef547e6afdbb5b462ce722c358934e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f626974647265616d69742f6c61726176656c2d717a2d747261792e737667)](https://packagist.org/packages/bitdreamit/laravel-qz-tray)[![License](https://camo.githubusercontent.com/5f073e7dfd347360844963cb34adb8168269a30450f87fa81fd40e139ec3d8ee/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f626974647265616d69742f6c61726176656c2d717a2d747261792e737667)](https://packagist.org/packages/bitdreamit/laravel-qz-tray)[![PHP Version](https://camo.githubusercontent.com/5ecf15058c4823ebb5a218b2da3b1e6e8784a4d2db2c9f6ecb97fb1fb99f35a8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f626974647265616d69742f6c61726176656c2d717a2d747261792e737667)](https://packagist.org/packages/bitdreamit/laravel-qz-tray)[![Laravel Version](https://camo.githubusercontent.com/60cb6cc74373766da500ad7c9f54b8bc2e5186f33cef38f4a326f1efaf50b327/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d392e7825374331302e7825374331312e7825374331322e782d627269676874677265656e2e737667)](https://laravel.com)

🎯 **What is This Package?**
---------------------------

[](#-what-is-this-package)

**Laravel QZ Tray** is a complete silent printing solution that connects your Laravel application to desktop printers via QZ Tray. It allows you to print directly from the browser without print dialogs, with smart caching, printer memory, and automatic fallback.

**Perfect for:** POS systems, receipt printing, label printing, invoices, reports, and any application needing silent, automated printing.

---

📁 **FINAL PACKAGE STRUCTURE**
-----------------------------

[](#-final-package-structure)

```
laravel-qz-tray/
├── composer.json                    # Package configuration
├── LICENSE                          # MIT License
├── README.md                        # This documentation
├── config/
│   └── qz-tray.php                  # Package configuration
├── database/
│   └── migrations/
│       └── 2024_01_01_000000_create_qz_print_jobs_table.php
├── routes/
│   ├── web.php                      # Web routes for QZ Tray
│   └── api.php                      # API routes (optional)
├── resources/
│   ├── js/
│   │   ├── smart-print.js           # Main printing library (23KB)
│   │   ├── smart-print.min.js       # Minified version (12KB)
│   │   ├── printer-switcher.js      # UI for switching printers
│   │   ├── printer-status.js        # Status indicator component
│   │   └── adapters/
│   │       ├── escpos.js            # ESC/POS thermal printer commands
│   │       ├── zpl.js               # ZPL label printer commands
│   │       └── raw-print.js         # Generic raw printing
│   └── installers/                  # QZ Tray installers
│       ├── qz-tray-windows.exe      # Windows installer
│       ├── qz-tray-linux.deb        # Linux installer
│       └── qz-tray-macos.pkg        # macOS installer
├── src/
│   ├── QzTrayServiceProvider.php    # Laravel service provider
│   ├── Console/
│   │   └── Commands/
│   │       ├── InstallQzTray.php    # Installation command
│   │       └── GenerateCertificate.php
│   └── Http/
│       └── Controllers/
│           └── QzSecurityController.php
└── storage/
    └── qz/
        ├── certificate.pem          # Auto-generated SSL certificate
        └── private-key.pem          # Auto-generated private key

```

---

🚀 **Step-by-Step Installation Guide**
-------------------------------------

[](#-step-by-step-installation-guide)

### **Step 1: Install via Composer**

[](#step-1-install-via-composer)

```
# Install the package
composer require bitdreamit/laravel-qz-tray
```

### **Step 2: Run the Installer**

[](#step-2-run-the-installer)

```
# This does everything automatically:
# - Publishes config
# - Generates SSL certificate
# - Publishes JavaScript files
# - Sets up routes
php artisan qz:install
php artisan qz:install --force
php artisan vendor:publish --provider="Bitdreamit\QzTray\QzTrayServiceProvider" --tag=qz-config --force
php artisan vendor:publish --provider="Bitdreamit\QzTray\QzTrayServiceProvider" --tag=qz-assets --force
php artisan vendor:publish --provider="Bitdreamit\QzTray\QzTrayServiceProvider" --tag=qz-blade --force
```

**What the installer does:**

1. ✅ Creates `config/qz-tray.php`
2. ✅ Generates SSL certificate in `storage/qz/`
3. ✅ Publishes JS files to `public/vendor/qz-tray/`
4. ✅ Sets up all necessary routes
5. ✅ Optional: Runs migrations

### **Step 3: Include JavaScript in Your Layout**

[](#step-3-include-javascript-in-your-layout)

Add to `resources/views/layouts/app.blade.php`:

```
>

```

### **Step 4: Install QZ Tray on Client Computers**

[](#step-4-install-qz-tray-on-client-computers)

Users need QZ Tray installed on their computers. Provide download links:

```

    Install Printer Software

        Download and install QZ Tray for silent printing:

             Download for Windows

             Download for Linux

             Download for macOS

            After installation, restart your browser and this page.

```

---

🖨️ **COMPLETE USAGE GUIDE**
---------------------------

[](#️-complete-usage-guide)

### **1. Basic Print Buttons**

[](#1-basic-print-buttons)

```

     Print Invoice

    Print 2 Copies

    Print with 2-second delay

```

### **2. Auto-Print on Page Load**

[](#2-auto-print-on-page-load)

```

@if(session('print_receipt'))

@endif
```

**Controller example for auto-print:**

```
public function storeOrder(Request $request)
{
    // Process order...
    $order = Order::create($request->all());

    return redirect()->route('order.confirmation', $order->id)
        ->with([
            'success' => 'Order placed successfully!',
            'auto_print' => true,
            'receipt_id' => $order->id,
        ]);
}

public function confirmation($id)
{
    $order = Order::find($id);

    return view('orders.confirmation', [
        'order' => $order,
        'auto_print' => session('auto_print', false),
    ]);
}
```

### **3. Advanced Printing Options**

[](#3-advanced-printing-options)

```

     Print 3 Copies

    Custom Print

function printMyDocument() {
    smartPrint('/documents/123.pdf', {
        printer: 'Receipt Printer',
        copies: 2,
        onComplete: function(job) {
            alert('Printed successfully!');
        }
    });
}

```

### **4. Raw Printing (Thermal Printers &amp; Labels)**

[](#4-raw-printing-thermal-printers--labels)

```

     Print Thermal Receipt

     Print Shipping Label

// Thermal receipt (ESC/POS)
function printThermalReceipt() {
    const receiptData = {
        storeName: "My Store",
        receiptNumber: "12345",
        items: [
            { name: "Item 1", price: "10.00", quantity: 2 },
            { name: "Item 2", price: "15.00", quantity: 1 },
        ],
        subtotal: "35.00",
        tax: "3.50",
        total: "38.50"
    };

    const commands = ESCPOS.createReceipt(receiptData);
    smartPrintESC(commands, 'Thermal Printer');
}

// Shipping label (ZPL)
function printShippingLabel() {
    const labelData = {
        fromName: "John Doe",
        fromAddress: "123 Street",
        toName: "Jane Smith",
        toAddress: "456 Avenue",
        trackingNumber: "TRK123456789"
    };

    const zpl = ZPL.createShippingLabel(labelData);
    smartPrintZPL(zpl, 'Label Printer');
}

```

### **5. Programmatic API Usage**

[](#5-programmatic-api-usage)

```
// Check if QZ Tray is connected
if (SmartPrint.isConnected()) {
    console.log('Ready to print!');
}

// Get current printer
const currentPrinter = await SmartPrint.getCurrentPrinter();
console.log('Current printer:', currentPrinter);

// Get all available printers
const printers = await SmartPrint.getPrinters();
console.log('Available printers:', printers);

// Set printer for current page
await SmartPrint.setPrinter('Label Printer');

// Print with options
const jobId = await SmartPrint.print('/documents/invoice.pdf', {
    printer: 'Office Printer',
    copies: 2,
    type: 'pdf'
});

// Listen for events
SmartPrint.on('connected', () => {
    console.log('Connected to QZ Tray!');
});

SmartPrint.on('job-completed', (event) => {
    console.log('Print job completed:', event.job);
    alert('Document printed successfully!');
});

SmartPrint.on('job-failed', (event) => {
    console.error('Print job failed:', event.error);
    alert('Printing failed. Please try again.');
});
```

### **6. Hotkey Feature**

[](#6-hotkey-feature)

**Default:** `Ctrl + Shift + P`

When pressed, shows a dialog to switch printers for the current page. The selection is remembered permanently for that URL.

[![Hotkey Demo](https://camo.githubusercontent.com/71c5c78869a18fe0b98ec21d4f931337760f1ef5a61f295be2dceffe101e3ff5/68747470733a2f2f7669612e706c616365686f6c6465722e636f6d2f343030783230303f746578743d5072696e7465722b53776974636865722b4469616c6f67)](https://camo.githubusercontent.com/71c5c78869a18fe0b98ec21d4f931337760f1ef5a61f295be2dceffe101e3ff5/68747470733a2f2f7669612e706c616365686f6c6465722e636f6d2f343030783230303f746578743d5072696e7465722b53776974636865722b4469616c6f67)

### **7. Printer Status Indicator**

[](#7-printer-status-indicator)

```

```

**Options:**

- `position`: `top-left`, `top-right`, `bottom-left`, `bottom-right`, `top-center`, `bottom-center`
- `showPrinterName`: Show current printer name
- `showConnection`: Show connection status
- `autoHide`: Automatically hide after delay
- `clickToSwitch`: Click to open printer switcher

---

🔧 **Configuration Reference**
-----------------------------

[](#-configuration-reference)

After publishing config (`php artisan vendor:publish --tag=qz-config`):

### **`config/qz-tray.php`**

[](#configqz-trayphp)

```
