LaravelDaily / laravel-invoices

Laravel package to generate PDF invoices from various customizable parameters

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add Custom Data To Invoice Item

kinger251285 opened this issue · comments

Is your feature request related to a problem? Please describe.
When creating invoice items i need the ability to add additional information to the product line that is not relevant to the title or description. One example could be a product disclaimer/agreement for certain products.

Describe the solution you'd like
Similar to the current invoice setCustomClass method but within the invoice item itself. I often loop through products pulled via the database to which need to be relevant on the invoice to the product. I could loop through this twice via the current invoice setCustomClass method but this seems inefficient.

Describe alternatives you've considered
As declared above i am currently going to add this to the overall invoice and loop through and compare the second array with the product title to display what is required. But again seems inefficient and could be easily added ( i considered updating the actual vendor files myself but don't want to run the risk of updates ovveriding and causing issues.

@kinger251285 you can easily extend InvoiceItem class and add there whatever you need

use LaravelDaily\Invoices\Classes\InvoiceItem;

class MyItem extends InvoiceItem
{
    public $myStuff;
    
    public function doMyStuff($data)
    {
        // ...
    }
}

$invoice = Invoice::make()->addItem((new MyItem())->doMyStuff($data));