【发布时间】:2020-12-14 18:29:02
【问题描述】:
我怎样才能让这个查询工作?
$basic_query = Invoices::between_days(15, 7); // This is a collection of invoices from 15 days ago, to seven days in the future. Notice I am not getting this query, it´s still just a builder instance. If you do dd($basic_query->get()) you get 100 invoices, 60 of them paid, 40 of them outstanding.
$paid_invoices = $basic_query->paid()->get(); // This returns the collection of 60 paid invoices without problems. BUT MODIFIES $basic query, if you dd($basic query->get()) at this point, you only get the 60 paid invoices, not the full 100 invoices collection. ¿?!!!
$outstanding_invoices = $basic_query->paid(false)->get(); // This query will always be empty, even though there are many outstanding invoices. If you dd($basic_query->get()) at this point, you get an empty collection. The 100 invoices are lost.
那么,我怎样才能有一个基本集合作为起点,不会被后续的 get() 操作修改。
谢谢!
【问题讨论】:
-
它们是“构建器”对象,它们构建查询,因此对它们的每次调用都会向它正在构建或执行的查询添加内容,但构建器始终保存您正在构建的查询
-
@OMR,是的,它会的。基本上这是同一个问题,但措辞不同......对不起,我之前错过了,但它从未出现在我的搜索中。