2017-05-22 1 views
0

가 쿼리를 얻기 위해 필요 isBeautiful 또는 isGreat 또는 둘 다.은 메이크업이 같은 테이블이있는이어야 하나 개의 조건

$avaliableitems = item::where("isAvaliable,1) 
        ->where("isBeautiful",1) 
        ->orWhere("isGreat",1)->get(); 

이것은 의사 코드이므로 작동하지 않습니다.

foreach($avaliableitems as $avaliableitem){ 
if($avaliableitem->isBeautiful == 1 || $avaliableitem->isGreat){ 

//do things 

} 
} 

그러나 앞서 언급 한 바와 같이 웅변으로 그것을 할 수있는 방법이 있는지 궁금 :

은 내가 alwaysjust 항목을받을 경우 1 = isavaliable 다음 루프 각 항목을 통해 할 수있는 것을 알고있다.

+1

이 $의 avaliableitems 시도 = 항목 :: 곳 ("isAvaliable, 1) -> orwhere ("isBeautiful ", 1) -> orWhere (" isGreat ", 1) -> get(); – JYoThI

답변

1

가까이 사용할 수 있습니다.

item::where('isAvaliable', 1) 
      ->where('t_Id', 2) 
      ->where(function($q) { 
       $q->where('isBeautiful', 1) 
       ->orWhere('isGreat', 1); 
      })->get(); 
1

Laravel의 쿼리 작성 도구는 Closure를 허용합니다. 그래서

,이 같은 작업을해야합니다 :

$availableItems = item::where('isAvailable',1) 
         ->where(function($query)) { 
          $query->whereNull('isBeautiful', 1) 
            ->orWhere('isGreat', 1) 
         }) 
         ->get(); 
관련 문제