Laravel 5雄辩的查询重用问题

Maha Dev

我正在使用Laravel 5雄辩的查询,但遇到了一些我不知道的技术问题。我想从同一个查询中提取两个单独的数组,它们的条件都不同,如下所示:

$articles = DB::table($this->table)
                ->select('articles.id','art.name');

$simpleTypes =  $articles->whereIn('articles.content_type',['Type 1','Type 2','Type 3'])->get();

$complexTypes = $articles->whereIn('articles.content_type',['Type 4','Type 5'])->get();

导入$simpleTypes但不导入数据$complexTypes

奥利姆·赛义多夫(Olim Saidov)

您需要克隆原始查询以重新使用它:

$articles = DB::table($this->table)
                ->select('articles.id','art.name');

$clonedQuery = clone $article;

$simpleTypes =  $articles->whereIn('articles.content_type',['Type 1','Type 2','Type 3'])->get();

$complexTypes = $clonedQuery->whereIn('articles.content_type',['Type 4','Type 5'])->get();

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章