Download the PHP package finller/laravel-invoices without Composer
On this page you can find all versions of the php package finller/laravel-invoices. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download finller/laravel-invoices
More information about finller/laravel-invoices
Files in finller/laravel-invoices
Package laravel-invoices
Short Description Store invoices safely in your Laravel application
License MIT
Homepage https://github.com/ElegantEngineeringTech/laravel-invoices
Informations about the package laravel-invoices
Everything You Need to Manage Invoices in Laravel
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.
Demo
Try out the interactive demo to explore package capabilities.
Table of Contents
-
Requirements
-
Installation
-
The Invoice Eloquent Model
- Storing an Invoice in Your Database
- Automatically Generating Unique Serial Numbers
- Managing Multiple Prefixes and Series
- Customizing the Serial Number Format
- Displaying Your Invoice as a PDF
- Attaching Your Invoice to an Email
- Customizing the PDF Invoice
- Adding a Dynamic Logo
-
The PdfInvoice Class
- Rendering the Invoice as a PDF
- Rendering the Invoice in a View
- Customization
- Customizing the Font
- Customizing the Template
Requirements
- PHP 8.1+
- Laravel 11.0+
dompdf/dompdf
for PDF renderingelegantly/laravel-money
for money computation
Installation
You can install the package via composer:
You can publish and run the migrations with:
You can publish the config file with:
This is the contents of the published config file:
The Invoice Eloquent Model
Storing an Invoice in Your Database
You can store an Invoice in your database using the Eloquent Model: Elegantly\Invoices\Models\Invoice
.
[!NOTE] Don't forget to publish and run the migrations
Here is a full example:
Automatically Generating Unique Serial Numbers
This package provides a simple and reliable way to generate serial numbers automatically, such as "INV240001".
You can configure the format of your serial numbers in the configuration file. The default format is PPYYCCCC
, where each letter has a specific meaning (see the config file for details).
When invoices.serial_number.auto_generate
is set to true
, a unique serial number is assigned to each new invoice automatically.
Serial numbers are generated sequentially, with each new serial number based on the latest available one. To define what qualifies as the previous
serial number, you can extend the Elegantly\Invoices\Models\Invoice
class and override the getPreviousInvoice
method.
By default, the previous invoice is determined based on criteria such as prefix, series, year, and month for accurate, scoped numbering.
Managing Multiple Prefixes and Series
In more complex applications, you may need to use different prefixes and/or series for your invoices.
For instance, you might want to define a unique series for each user, creating serial numbers that look like: INV0001-2400X
, where 0001
represents the user’s ID, 24
the year and X
the index of the invoice.
[!NOTE] When using IDs for series, it's recommended to plan for future growth to avoid overflow. Even if you have a limited number of users now, ensure that the ID can accommodate the maximum number of digits allowed by the serial number format.
When creating an invoice, you can dynamically specify the prefix and series as follows:
Customizing the Serial Number Format
In most cases, the format of your serial numbers should remain consistent, so it's recommended to set it in the configuration file.
The format you choose will determine the types of information you need to provide to configureSerialNumber
.
Below is an example of the most complex serial number format you can create with this package:
Displaying Your Invoice as a PDF
The Invoice model has a toPdfInvoice()
that return a PdfInvoice
class.
You can stream the PdfInvoice
instance as a response, or download it:
Attaching Your Invoice to an Email
The Invoice
model provide a toMailAttachment
method making it easy to use with Mailable
Customizing the PDF Invoice
To customize how your model is converted to a PdfInvoice
, follow these steps:
-
Create a Custom Model: Define your own
\App\Models\Invoice
class and ensure it extends the base\Elegantly\Invoices\Models\Invoice
class. -
Override the
toPdfInvoice
Method: Implement your specific logic within thetoPdfInvoice
method to control the customization. - Update the Configuration File: Publish the package configuration file and update the
model_invoice
key as shown below:
Adding a Dynamic Logo
If you need to set the logo dynamically on the invoice, for example, when allowing users to upload their own logo, you can achieve this by overriding the getLogo
method. Follow the steps outlined in the Customizing the PDF Invoice section to create your own Model.
To dynamically set the logo, define the getLogo
method as shown below:
[!NOTE]
The returned value must be either a base64-encoded data URL or a path to a locally accessible file.
The PdfInvoice Class
This package includes a standalone PdfInvoice
class, making it easy to render invoices as a PDF or directly within a view.
You can even use this package exclusively for the PdfInvoice
class if that suits your needs.
Here’s an example of a fully configured PdfInvoice
instance:
Rendering the Invoice as a PDF
In a Controller
In a Livewire Component
Store in a file
Rendering the Invoice in a View
You can render your invoice within a larger view, enabling you to create an "invoice builder" experience similar to the interactive demo.
To achieve this, include the main part of the invoice in your view as shown below:
This approach allows you to seamlessly integrate the invoice into a dynamic and customizable user interface.
[!NOTE]
The default template is styled using Tailwind-compatible syntax, making it seamlessly compatible with websites that use Tailwind.
If you don’t use Tailwind, the styling may not render as intended.
Customization
Customizing the Font
See the Dompdf font guide.
Customizing the Template
To customize the invoice template, you can publish the provided views and modify them as needed.
Alternatively, you can create a completely custom template. Ensure that your custom template follows the same structure and conventions as the default one to maintain compatibility with various use cases.
Testing
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
- Quentin Gabriele
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-invoices with dependencies
dompdf/dompdf Version ^3.1
elegantly/laravel-money Version ^2.1.0
illuminate/contracts Version ^11.0||^12.0
spatie/laravel-package-tools Version ^1.14