[英]Laravel Receipt items add
我正在使用laraveldaily/laravel-invoices
生成發票。
在文檔中,該項目是手動添加的。
$items = [
(new InvoiceItem())->title('Service 12')->pricePerUnit(92.82),
(new InvoiceItem())->title('Service 13')->pricePerUnit(12.98),
];
但是,如果我有 10 個或更多產品,那么如何使用 foreach 循環或任何其他方式添加項目?
$items = array();
foreach($products as $product)
{
$items = [
(new InvoiceItem())->title('Service')->pricePerUnit(92.82),
];
}
它不工作。 我怎樣才能做到這一點?
在編寫循環時,您只需在每個循環上設置數組。 您需要推送每個元素:
foreach($products as $product) {
$items []= (new InvoiceItem())->title('Service')->pricePerUnit(92.82);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.