문제

 $query = new TableA;
 $query = $query->join('tableB', 'tableA.b_id', '=', 'tableB.id');
 $query = $query->where('tableB.something', '=', '1');
 $query = $query->where('tableA.something_else', '=', '2');

And it produces:

 WHERE something=1 AND something_else=2 AND .. AND....

BUT now - I need this:

 WHERE something=1 AND something_else=2 AND (city=city1 OR city=city2 OR city=city3) AND (country=country1 OR country=country2)

Any ideas?

도움이 되었습니까?

해결책

Make use of Advanced Wheres. For your example, it'd be something like this:

    ->where(function ($query) {
       $query->where('city', '=', city1)
             ->orWhere('city', '=', city2)
             ->orWhere('city', '=', city3);
    })->where(function ($query) {
       $query->where('country', '=', country1)
             ->orWhere('country', '=', country2);
    });

다른 팁

Quick method. Read about raw expressions:

http://laravel.com/docs/queries#raw-expressions

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top