- Which PDF library does this package use under the hood, and how does it handle performance for high-volume invoices?
- The package relies on DomPDF by default, a lightweight PHP library for PDF generation. For high-volume invoices, consider queueing PDF generation using Laravel’s queue system (e.g., `dispatch()`) to avoid timeouts or server overload. The package itself doesn’t enforce async handling, so you’ll need to implement it manually if required.
- How do I map my existing Laravel models (e.g., Order, Product) to the invoice data structure expected by this package?
- The package expects an array with keys like `customer`, `items`, `subtotal`, etc. You can transform your Eloquent models into this format using a custom data mapper class or directly in your controller. For example, loop through `Order::with('items')->get()` and format the output to match the package’s requirements.
- Can I customize the invoice template beyond the published Blade file, or are there hooks for extending functionality?
- Yes, the package publishes a Blade template to `resources/views/vendor/invoice/template.blade.php`, which you can fully customize. For deeper extensibility, you can override the template path in the `config/invoice.php` file or create a custom template class by extending the package’s base renderer. There are no built-in hooks, but you can subclass the facade or service provider for additional logic.
- Does the package support multi-language invoices (e.g., RTL languages like Arabic) or dynamic tax rules per region?
- The package supports multi-language and currency formatting via Laravel’s localization features, but RTL languages may require manual CSS adjustments in the Blade template. Dynamic tax rules aren’t natively supported; you’ll need to extend the `config/invoice.php` or override the tax calculation logic in your custom template or service provider.
- How do I secure the QR code links generated for invoices? Can I integrate with Laravel Sanctum or Passport for authentication?
- The QR code link is generated from the `qr_code_link` field in your invoice data. To secure access, generate time-limited or tokenized URLs (e.g., using Laravel Sanctum or Passport) and include them in the invoice data. For example, use `route('invoice.preview', ['token' => $secureToken])` to create a link that requires authentication.
- What happens if PDF generation fails? Are there retries, rollbacks, or error handling mechanisms built into the package?
- The package doesn’t include built-in retry or rollback logic for failed PDF generation. If DomPDF throws an exception (e.g., due to memory limits or invalid data), it will propagate to your code. Handle errors in your controller or middleware, and consider logging failures for debugging. For critical invoices, implement a queue job with retries.
- Is there built-in testing support for this package, or will I need to write integration tests for my custom templates?
- The package doesn’t include pre-written tests, but you can test its core functionality using Laravel’s testing tools. Mock the invoice data and verify PDF output by comparing generated files or preview HTML. For custom templates, test edge cases like long item descriptions, multi-line addresses, or special characters to ensure rendering integrity.
- Can I swap the PDF engine (e.g., from DomPDF to SnappyPDF) without forking the package?
- The package abstracts the PDF generation logic, so you can replace DomPDF with another library like SnappyPDF by binding a custom PDF renderer to the service container. Override the `pdf` binding in your `AppServiceProvider` or create a custom service provider to inject your preferred engine. This requires minimal changes to the package’s core.
- How do I preview invoices in the browser before generating the final PDF? Does the package support live updates?
- The package provides a `preview()` method that renders the invoice as HTML for browser display. This uses the same Blade template as the PDF but outputs raw HTML. For live updates (e.g., editing invoice data before generation), trigger the preview in a Laravel route or API endpoint and pass dynamic data via a form or JavaScript.
- Are there alternatives to this package for Laravel invoices, and what makes this one stand out?
- Alternatives include `barryvdh/laravel-dompdf` (simpler but less feature-rich) or `spatie/laravel-invoice` (more opinionated with built-in models). This package stands out for its Blade-based customization, fluent API, and optional QR code support. It’s ideal if you need fine-grained control over templates and branding without bloating your project with unnecessary dependencies.