2017-09-18 1 views
0

다른 구독 유형을 가진 사람들이 아닌 특정 구독을 사용하는 모든 사람을 얻으려는 구문 분석 문제가 있습니다. 구독은 구독 열의 구독 테이블에 쉼표로 구분 된 목록에 저장됩니다. 지금까지 가지고있는 코드는 다음과 같습니다.여러 개의 Eloquent Where 매개 변수가 여러 개의 매개 변수가있는 경우

 $includeQuery = []; 
     foreach ($includeSegment as $include) { 
      $singleQuery = ['subscriptions','like', '%'.$include.'%', 'or']; 
      array_push($includeQuery, $singleQuery); 
     } 
     $excludeQuery = []; 
     foreach ($excludeSegment as $exclude) { 
      $singleQuery = ['subscriptions', 'not like', '%'.$exclude.'%', 'or']; 
      array_push($excludeQuery, $singleQuery); 
     } 

     $included = Subscription::where($excludeQuery)->where($includeQuery)->get(); 

결과가 돌아 왔지만 일부는 제외 된 구독이 있습니다.

+0

where 절 내에 쿼리 함수를 사용하면 도움이됩니까? –

답변

0

의 배열 일단 또한 세그먼트를 반복 할 필요 없어요. 따라서 특정 사용자에 대한 모든 구독이 존재하는 경우에만 레코드가 삭제됩니다. 다음은 업데이트 된 코드입니다.

 $includeQuery = []; 
     foreach ($includeSegment as $include) { 
      $singleQuery = ['subscriptions','like', '%'.$include.'%', 'or']; 
      array_push($includeQuery, $singleQuery); 
     } 
     $excludeQuery = []; 
     foreach ($excludeSegment as $exclude) { 
      $singleQuery = ['subscriptions', 'not like', '%'.$exclude.'%', 'and']; 
      array_push($excludeQuery, $singleQuery); 
     } 

//  $included = Subscription::where($excludeQuery)->where($includeQuery)->get(); 
     $included = DB::table('subscriptions') 
      ->join('app_users', 'app_users.customer_number', '=', 'subscriptions.customer_number') 
      ->join('app_datas', 'app_datas.customer_number', '=', 'subscriptions.customer_number') 
      ->where($includeQuery) 
      ->where($excludeQuery) 
      ->select('app_datas.device_token') 
      ->get(); 
+1

그래서 해결 되었습니까? 좋은! – Arty

0

사용하는 것을 특징으로 whereNotIn 대신 :

구독 :: 항에있어서, ($ includeSegment) -> whereNotIn ($ excludeSegment) -> (GET);

는 당신은 그들이 코드 문제는 위의 I "또는"대신했다 "와"부울 매개 변수에 있었다 문자열

+1

오케이, 방금 컬럼이 쉼표로 분리 된 값을 가지고 있다는 것을 깨달았습니다. 따라서 분명히 작동하지 않을 것입니다 – Markownikow

+0

그러면 whereRaw() 및 mysql LOCATE 함수, ​​https://dev.mysql.com/doc/refman/5.7/en으로 시도해야합니다. /string-functions.html#function_locate – Markownikow