어떻게 1로, 병합 또는 노동 조합이 2 개 개의 쿼리를 조인 웅변 쿼리를 작성하려면 어떻게해야합니까?

조쉬 :

// 2 개 eloqent 컬렉션은 합병

$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);

//이 쿼리는 위의 중복이 2 개 MySQL의 쿼리를 수행합니다.

여기에 이미지 설명을 입력

이에서 결과는하지만,이 쿼리를 필요로 맞습니다.
어떻게 1로, 병합 또는 노동 조합이 2 개 개의 쿼리를 조인 웅변 쿼리를 작성하려면 어떻게해야합니까?

딜립 Hirapara :

이유는 따로 있어요? 당신은 사용할 수 있습니다 Orwhere이것을.

$publicprivateCategories = Category::where('menu', '=', 1)
                        ->whereIn('id', $ids)
                        ->orWhere('display_scope', 1)
                        ->orderBy('parent_id')
                        ->get();

최신 정보

$publicprivateCategories = Category::where('menu', '=', 1)
                        ->where(function($q) use($ids){
                             $q->whereIn('id', $ids)->orWhere('display_scope', 1);
                        })
                        ->where('id', '!=', 2)
                        ->orderBy('parent_id')
                        ->get();

이하면 (공공 또는 개인) 부문 모두를 얻을 수 있습니다.

추천

출처http://43.154.161.224:23101/article/api/json?id=13600&siteId=1