Laravel 如何重用对性能有很多关系

问题描述

我正在尝试按如下方式重用对 has-many-Relationship 的调用

//myModelEntries is the has-many-Relationship
$entries = $myModel->myModelEntries();

$firstUseCase = $entries
                   //->where(...)
                   //->select(...)
                   //->get()
                   //->map(...)
                   //->all()

$secondUseCase = $entries
                   // append some other querybuilder functions

遗憾的是,$entries 不能以这种方式重用,因为第一次使用以某种方式改变了 $entries 变量。因此,我第二次使用 $entries 时,此变量的行为方式与 $myModel->myModelEntries() 不同。

完成这项工作的最佳方法是什么?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)