【发布时间】:2020-02-17 04:55:25
【问题描述】:
// 2 eloqent collections 合并
$publicCategories = Category::where('menu', '=', 1)
->where('display_scope', 1)
->orderBy('parent_id')
->get();
$privateCategories = Category::where('menu', '=', 1)
->whereIn('id', $ids)
->orderBy('parent_id')
->get();
$categories = $publicCategories->merge($privateCategories);
// 上面的这个查询执行了这两个重复的 MySQL 查询。
此结果是正确的,但是需要 2 次查询。
如何编写一个雄辩的查询,将这 2 个查询连接、合并或联合为 1 个?
【问题讨论】: