Description
This package provides a robust, easy-to-use system for managing invoices within a Laravel application, with options for database storage, serial numbering, and PDF generation.
The PdfInvoice Class
This package provides a powerful, standalone PdfInvoice class. Its main functionalities include the ability to:
- Display your invoice as a PDF document.
- Render your invoice within a Blade view.
The PdfInvoice class is also integrated with the Invoice Eloquent Model, allowing you to easily convert an Invoice model instance into its PDF representation.
You can even use this package exclusively for the PdfInvoice class if you don't require database storage for your invoices.
Full Example
use \Elegantly\Invoices\Pdf\PdfInvoice;use \Elegantly\Invoices\Pdf\PdfInvoiceItem;use \Elegantly\Invoices\Support\Seller;use \Elegantly\Invoices\Support\Buyer;use \Elegantly\Invoices\Support\Address;use \Elegantly\Invoices\Support\PaymentInstruction;use \Elegantly\Invoices\InvoiceDiscount;use Brick\Money\Money; $pdfInvoice = new PdfInvoice( name: "Invoice", state: "paid", serial_number: "INV-241200001", seller: new Seller( company: 'elegantly', name: 'Quentin Gabriele', // (optional) address: new Address( street: "Place de l'Opéra", city: 'Paris', postal_code: '75009', country: 'France', ), tax_number: 'FR123456789', fields: [ // Custom fields to display with the seller "foo" => "bar" ] ), buyer: new Buyer( company: "Doe Corporation" // (optional) name: 'John Doe', // (optional) address: new Address( street: '8405 Old James St.Rochester', city: 'New York', postal_code: '14609', state: 'NY', country: 'United States', ), shipping_address: new Address( // (optional) street: [ // multiple lines street '8405 Old James St.Rochester', 'Apartment 1', ], city: 'New York', postal_code: '14609', state: 'NY', country: 'United States', ), fields: [ // Custom fields to display with the buyer "foo" => "bar" ] ), description: "An invoice description", created_at: now(), due_at: now(), paid_at: now(), tax_label: "VAT France (20%)", fields: [ // custom fields to display at the top 'Order' => "PO0234" ], items: [ new PdfInvoiceItem( label: "Laratranslate Unlimitted" , unit_price: Money::of(99.0, 'USD'), tax_percentage: 20.0, quantity: 1, description: "Elegant All-in-One Translations Manager for Laravel", ), ], discounts: [ new InvoiceDiscount( name: "Summer offer", code: "SUMMER", percent_off: 50, ) ], paymentInstructions: [ new PaymentInstruction( name: 'Bank Transfer', description: 'Make a direct bank transfer using the details below.', qrcode: 'data:image/png;base64,' . base64_encode( file_get_contents(__DIR__.'/../resources/images/qrcode.png') ), fields: [ 'Bank Name' => 'Acme Bank', 'Account Number' => '12345678', 'IBAN' => 'GB12ACME12345678123456', 'SWIFT/BIC' => 'ACMEGB2L', 'Reference' => 'INV-0032/001', '<a href="#">Pay online</a>', ], ), ], logo: public_path('/images/logo.png'), // local path or base64 string template: "default.layout", // use the default template or use your own templateData: [ // custom data to pass to the template 'color' => '#050038' ],);
Rendering the Invoice as a PDF
namespace App\Http\Controllers; use Elegantly\Invoices\Pdf\PdfInvoice; class InvoiceController extends Controller{ public function showAsPdf() { $pdfInvoice = new PdfInvoice( // ... ); return $pdfInvoice->stream(); }}
Recent Courses on Laravel Daily
Next.js Basics for Laravel Developers
11 lessons
58 min
Laravel 13 Starter Kit Teams and Customizations
10 lessons
33 min
Roles and Permissions in Laravel 13
14 lessons
57 min