繁体   English   中英

Laravel 收货项目添加

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM