![](/img/trans.png)
[英]How to use Carbon date in where clause in Laravel Collection
[英]Laravel collection where clause
Laravel是否有可能将条件应用于某个集合,并将该结果放入另一个集合而无需更改第一个集合?
例如:
$documenti = DB::table("RVW_DocumentiDettaglio")
->select("*")
->where("IDAzienda", "=", $request->session()->get("operatore.IDAzienda"))
->whereIn("CodiceStato", [Documento::E_DOC, Documento::W_DOC, Documento::OK_DOC])
->orderBy("IDDocumentoTestata", "asc");
// Ciclo le voci spesa
foreach ($voci_spesa as $voce_spesa) {
Log_Controller::debug("Documenti:" . $documenti->get());
if ($voce_spesa["Manuale"]) {
$dettaglio = $documenti->where("Descrizione", "like", "%" . $voce_spesa["Descrizione"] . "%");
} else {
$dettaglio = $documenti->where("Descrizione", "=", $voce_spesa["Descrizione"]);
}
Log_Controller::debug("Dettaglio:" . $dettaglio->get());
}
die;
使用$documenti
我得到了第一个集合,在foreach中,我应用了where条件并将结果放入$dettaglio
集合中,但是第一个集合( $documenti
)也被更改了。 为什么? 就像共享对象
当然,您可以将where子句与Collections一起应用,还可以使用许多其他方法,包括过滤和映射。 请参阅此处的文档:
$collection = Item::all();
$filtered = $collection->where('price', 100);
$filtered->all();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.