我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),
];
}
它不作業。 我怎樣才能做到這一點?
uj5u.com熱心網友回復:
在撰寫回圈時,您只需在每個回圈上設定陣列。您需要推送每個元素:
foreach($products as $product) {
$items []= (new InvoiceItem())->title('Service')->pricePerUnit(92.82);
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/433752.html
