Installation
composer require tomatophp/filament-invoices
Publish the package assets and config:
php artisan vendor:publish --provider="TomatoPHP\FilamentInvoices\FilamentInvoicesServiceProvider" --tag="filament-invoices-config"
php artisan vendor:publish --provider="TomatoPHP\FilamentInvoices\FilamentInvoicesServiceProvider" --tag="filament-invoices-assets"
Run Migrations
php artisan migrate
Register the Plugin
Add to app/Providers/Filament/AdminPanelProvider.php:
public function panel(Panel $panel): Panel
{
return $panel
->plugins([
\TomatoPHP\FilamentInvoices\FilamentInvoicesPlugin::make(),
]);
}
First Use Case
config/filament-invoices.php (currency settings, default templates, email configurations).resources/views/vendor/filament-invoices/ (customize or extend built-in templates).\TomatoPHP\FilamentInvoices\Facades\FilamentInvoices (for programmatic invoice generation).InvoiceStatsWidget) can be added to Filament dashboards.Use the facade to create invoices dynamically (e.g., after an order is placed):
use TomatoPHP\FilamentInvoices\Facades\FilamentInvoices;
$invoice = FilamentInvoices::create([
'client_id' => $customer->id,
'currency' => 'USD',
'items' => [
['name' => 'Product A', 'quantity' => 2, 'unit_price' => 10.00],
],
'template' => 'modern', // Uses built-in templates
]);
Attach invoices to any model using morphTo/morphWith:
// In your model (e.g., Order.php)
public function invoice()
{
return $this->morphOne(Invoice::class, 'invoiceable');
}
// Generate invoice for an order
$order->invoice()->create([...]);
Link payments to invoices and track statuses:
$invoice->payments()->create([
'amount' => 50.00,
'method' => 'credit_card',
'status' => 'completed',
]);
Send invoices via email with PDF attachments:
$invoice->sendEmail([
'to' => $client->email,
'subject' => 'Your Invoice #'.$invoice->number,
]);
Add invoice stats to your Filament dashboard:
use TomatoPHP\FilamentInvoices\Widgets\InvoiceStatsWidget;
public function getWidgets(): array
{
return [
InvoiceStatsWidget::class,
];
}
Extend the factory pattern to add new templates:
resources/views/vendor/filament-invoices/templates/.'templates' => [
'custom' => 'filament-invoices::templates.custom',
],
Customize invoice statuses via the statuses config array:
'statuses' => [
'draft' => ['label' => 'Draft', 'color' => 'gray'],
'sent' => ['label' => 'Sent', 'color' => 'blue'],
'paid' => ['label' => 'Paid', 'color' => 'green'],
],
Set default currency and exchange rates in config/filament-invoices.php:
'currency' => [
'default' => 'USD',
'rates' => [
'EUR' => 0.85,
'GBP' => 0.75,
],
],
Migration Conflicts
invoices or invoice_items tables, drop them before running migrations to avoid conflicts.Template Overrides
@extends('filament-invoices::layouts.invoice')) or they may break PDF generation.DomPDF Dependencies
dompdf/dompdf is installed and configured. Run:
composer require dompdf/dompdf
Email Attachments
storage directory is writable and the filament-invoices.email config is set:
'email' => [
'from' => 'invoices@yourdomain.com',
'pdf_path' => storage_path('app/invoices'),
],
Morph Relationships
morphTo, ensure the invoiceable_type and invoiceable_id columns exist in the invoices table (they are included by default).Log Invoice Creation Enable logging in the config to debug issues:
'debug' => env('FILAMENT_INVOICES_DEBUG', false),
Check PDF Generation Test PDF generation locally before deploying:
$pdf = $invoice->generatePdf();
Storage::disk('local')->put('test.pdf', $pdf);
Validate Config
Use php artisan config:clear if changes to filament-invoices.php aren’t reflected.
Clear Cached Views If template changes aren’t showing, run:
php artisan view:clear
Custom Invoice Models
Extend the Invoice model to add fields:
use TomatoPHP\FilamentInvoices\Models\Invoice as BaseInvoice;
class Invoice extends BaseInvoice
{
protected $casts = [
'tax_exempt' => 'boolean',
];
}
Hooks for Pre/Post Actions Use events to intercept invoice creation/updates:
// In EventServiceProvider
InvoiceCreated::listen(function ($invoice) {
// Add custom logic (e.g., notify admin)
});
API Endpoints Expose invoice data via Laravel API routes:
Route::get('/invoices/{invoice}', [InvoiceController::class, 'show']);
Localization
Override labels/translations in resources/lang/en/filament-invoices.php:
return [
'invoices' => [
'title' => 'Bills',
],
];
How can I help you explore Laravel packages today?