Question

 $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?

Was it helpful?

Solution

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

OTHER TIPS

Quick method. Read about raw expressions:

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top