laraveldaily/laravel-invoices
Generate customizable PDF invoices in Laravel with templates, translations, taxes/discounts/shipping, due dates, serial numbers, and flexible currency formatting. Store, download, or stream via any configured filesystem, with global settings and per-invoice overrides.
Installation:
composer require laraveldaily/laravel-invoices:^4.1.1
php artisan invoices:install
This publishes views, translations, and config to your project.
First Invoice:
use LaravelDaily\Invoices\Invoice;
use LaravelDaily\Invoices\Classes\Buyer;
use LaravelDaily\Invoices\Classes\InvoiceItem;
$invoice = Invoice::make()
->buyer(new Buyer(['name' => 'John Doe']))
->addItem(InvoiceItem::make('Service')->pricePerUnit(100))
->stream();
Key Directories:
resources/views/vendor/invoices/templates/config/invoices.phpresources/lang/vendor/invoices/Invoice Creation:
Invoice::make('receipt') // Optional type (e.g., 'receipt', 'proforma')
->seller($sellerParty)
->buyer($buyerParty)
->addItems($items)
->taxRate(15)
->discountByPercent(10);
Dynamic Overrides: Use method chaining to override config values per invoice:
->dateFormat('m/d/Y')
->currencySymbol('$')
->serialNumberFormat('{SERIES}-{SEQUENCE}')
File Handling:
// Stream to browser
$invoice->stream();
// Download
$invoice->download();
// Save to disk (e.g., 'public')
$invoice->save('public');
// Get URL (if saved)
$invoice->url();
Custom Data: Attach arbitrary data to invoices for template use:
$invoice->setCustomData(['project_id' => 123]);
// Access in template via `$invoice->customData`
With Eloquent Models:
// Attach invoice data to a model
$order->invoice = $invoice->toHtml(); // Store HTML or PDF path
$order->save();
Email Integration:
Mail::to($buyer->email)->send(new InvoiceMail($invoice));
Batch Processing:
foreach ($orders as $order) {
$invoice = Invoice::make()
->buyer($order->customer)
->addItems($order->items)
->save('invoices');
// Queue email or notification
}
Template Customization:
Extend the default template (default.blade.php) by copying it to resources/views/vendor/invoices/templates/your_template.blade.php and referencing it:
Invoice::make()->template('your_template');
Logo Paths:
public_path('images/logo.png')) or base64 encoding:
$invoice->logo(base64_encode(file_get_contents('logo.png')));
Currency Formatting:
currencyDecimalPoint and currencyThousandsSeparator match your locale (e.g., , vs . for decimals).Serial Number Conflicts:
sequence in config or via:
$invoice->sequence($nextSequence);
Template Caching:
php artisan view:clear) after modifying templates.Locale-Specific Issues:
config/app.php) or override dynamically:
$invoice->getAmountInWords($total, 'es_ES'); // Spanish
Inspect Invoice Data:
dd($invoice->toArray()); // Dump raw invoice data
Check Template Rendering:
Use toHtml() to preview the template before PDF generation:
return $invoice->toHtml();
Log Errors: Wrap invoice generation in a try-catch:
try {
$invoice->stream();
} catch (\Exception $e) {
Log::error('Invoice generation failed: ' . $e->getMessage());
}
Custom Party Classes:
Extend LaravelDaily\Invoices\Classes\Party to add fields:
class CustomBuyer extends Party {
public function getVatNumber() { ... }
}
Update config:
'buyer' => [
'class' => \App\CustomBuyer::class,
]
Dynamic Serial Numbers:
Override getSerialNumber() in a custom invoice class:
class CustomInvoice extends Invoice {
public function getSerialNumber() {
return 'CUST-' . $this->sequence;
}
}
Hooks for Post-Generation:
Use events (e.g., invoice.saved) via Laravel’s event system to trigger actions after saving:
event(new InvoiceSaved($invoice));
Multi-Currency Support: Dynamically set currency per invoice:
$invoice->currencyCode('EUR')->currencySymbol('€');
Use Facades for Conciseness:
Invoice::makeParty(['name' => 'Client'])
->addItem(Invoice::makeItem('Service')->pricePerUnit(50))
->stream();
Leverage setCustomData for Metadata:
$invoice->setCustomData([
'terms' => 'Net 30',
'reference' => $order->reference,
]);
Batch Generate Invoices:
$invoices = collect($orders)->map(function ($order) {
return Invoice::make()
->buyer($order->customer)
->addItems($order->items)
->save('invoices');
});
How can I help you explore Laravel packages today?