I'm using laraveldaily/laravel-invoices
to generate invoices.
Here in the docs, the item was added manually.
$items = [
(new InvoiceItem())->title('Service 12')->pricePerUnit(92.82),
(new InvoiceItem())->title('Service 13')->pricePerUnit(12.98),
];
But, if I have 10 or more products then how can I add items using foreach loop or any other way?
$items = array();
foreach($products as $product)
{
$items = [
(new InvoiceItem())->title('Service')->pricePerUnit(92.82),
];
}
It's not working. How Can I do this?
As you wrote your loop, you just set the array on each loop. You need to push each element:
foreach($products as $product) {
$items []= (new InvoiceItem())->title('Service')->pricePerUnit(92.82);
}