简体   繁体   English

Laravel/Php - 在急切加载关闭中修改集合?

[英]Laravel/Php - Modify the collection in eager loading closure?

I'm trying to modify this query:我正在尝试修改此查询:

急切加载查询

The function of the helper class returns me the products left by removing the amounts used in sales, etc. It works fine if I use dd() inside the function.助手 class 的 function 通过删除销售中使用的金额等将剩余的产品返回给我。如果我在 function 中使用 dd(),它工作正常。 However, the $products collection isn't changed, what am I missing to successfully modify the base $products array with the collection returned by the helper?但是, $products 集合没有改变,我缺少什么来成功修改基本 $products 数组与帮助器返回的集合?

If it helps, here is the helper class:如果有帮助,这里是助手 class:

助手类

If there is a better way to handle this, I am glad for every suggestion.如果有更好的方法来处理这个问题,我很高兴每一个建议。

Best regards此致

Edit:编辑:

I've tried the answer in the comment to pass the helper as closure parameter but still no luck.我已经在评论中尝试了将帮助程序作为闭包参数传递的答案,但仍然没有运气。

闭包实现

I think you have to add a return inside the with orders function我想你必须在命令 function 里面添加一个return

return Helper::calculateNumberOfQuantityLeftPerOrder($query->get());

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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