Laravel 收据项目添加
我正在使用 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),
];
}
它不起作用。 我该如何做到这一点?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您编写循环时,只需在每个循环上设置数组即可。您需要推送每个元素:
As you wrote your loop, you just set the array on each loop. You need to push each element: