laraveldaily/laravel-invoices
Generate customizable PDF invoices in Laravel with taxes, discounts, shipping, due dates, serial numbers, templates and translations. Store, download or stream via any configured filesystem, with flexible currency formatting and per-invoice overrides.
Installation:
composer require laraveldaily/laravel-invoices:^4.1.1
php artisan invoices:install
This publishes assets, views, translations, and config.
First Use Case: Generate a simple invoice in a controller:
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();
config/invoices.php – Global settings for serial numbers, currency, seller details, etc.resources/views/vendor/invoices/templates/ – Customize invoice layouts.Invoice::make() – Quick access to core functionality without manual imports.Define Parties:
$seller = Invoice::makeParty(['name' => 'Your Company']);
$buyer = Invoice::makeParty(['name' => 'Client']);
Create Items:
$item = Invoice::makeItem('Product')
->pricePerUnit(50)
->quantity(2)
->taxByPercent(10);
Build Invoice:
$invoice = Invoice::make()
->seller($seller)
->buyer($buyer)
->addItems([$item1, $item2])
->taxRate(5)
->shipping(5)
->save('public'); // Save to disk
Output:
return $invoice->stream(); // Display in browser
// OR
return $invoice->download(); // Force download
Dynamic Data: Attach custom data to invoices for templates:
$invoice->setCustomData(['project_id' => 123]);
Access in template via $invoice->customData.
Localization:
Override translations in resources/lang/vendor/invoices/.
Use getAmountInWords() with locales:
$invoice->getTotalAmountInWords('es'); // Spanish
Templates:
Extend default.blade.php or create new templates in resources/views/vendor/invoices/templates/.
Specify template:
$invoice->template('custom_template');
Automation:
Use Invoice::make() facade in queues/jobs for batch invoice generation:
Invoice::make()->buyer($client)->addItem($item)->save('s3');
Validation:
Validate Buyer/Seller data before passing to Invoice::make():
$buyer = new Buyer(['name' => 'Client', 'email' => 'client@example.com']);
if (!$buyer->isValid()) { /* Handle errors */ }
Template Paths:
php artisan invoices:install) breaks custom templates.php artisan vendor:publish --tag=invoices.views --force if missing.Serial Number Conflicts:
sequence_padding in config or manually override:
$invoice->sequence(1000)->sequencePadding(6);
Currency Formatting:
currencyFormat or decimal_point can break PDF rendering.formatCurrency(1234.56) before generating invoices.Logo Paths:
logo() fail in production.storage_path():
$invoice->logo(storage_path('app/public/logo.png'));
Disk Permissions:
save() fails silently if the disk lacks write permissions.config('invoices.disk') and permissions:
chmod -R 755 storage/app/public
Check Generated HTML:
Use toHtml() to debug template rendering:
$html = $invoice->toHtml();
// Inspect $html for issues
Log Serial Numbers: Add logging for sequence generation:
\Log::info('Invoice Serial:', ['serial' => $invoice->getSerialNumber()]);
Validate Data:
Use dd($invoice->getCustomData()) to inspect attached data in templates.
Custom Party Classes:
Extend Party or implement PartyContract for custom logic:
class CustomBuyer extends Party {
public function getTaxId() { return $this->custom_fields['tax_id'] ?? null; }
}
Hooks:
Override methods like getTotalAmount() in a custom invoice class:
class CustomInvoice extends Invoice {
public function getTotalAmount() {
return parent::getTotalAmount() * 1.1; // Add 10% fee
}
}
Dynamic Templates: Use Blade directives to conditionally render sections:
@if($invoice->hasShipping())
<tr><td>Shipping</td><td>{{ $invoice->shipping }}</td></tr>
@endif
Event Listeners: Listen for invoice generation events (if using Laravel events):
Invoice::created(function ($invoice) {
\Log::info('Invoice created:', $invoice->getSerialNumber());
});
Batch Processing: Use Laravel queues to generate invoices asynchronously:
Invoice::dispatch($invoiceData)->onQueue('invoices');
Multi-Currency: Store currency settings per invoice:
$invoice->currencyCode('EUR')->currencySymbol('€');
PDF Customization:
Use dompdf options via config:
config(['invoices.pdf_options' => ['defaultFont' => 'DejaVu Sans']]);
Testing:
Mock Invoice in tests:
$invoice = Mockery::mock(Invoice::class);
$invoice->shouldReceive('stream')->andReturn('pdf-content');
How can I help you explore Laravel packages today?