Laravel - Use OR inside the Where

Asked

Viewed 213 times

2

I’m using the remote ->cont to count the return number, and for that I put a condition using the ->WHERE but when I try to put a || in the condition of the error he searched and I can not find the answer.

code that I’m using:

$numrow1=DB::table('teste') 
                ->where('IdDesafiante','=',15 )
                        ->count();

as I’ve tried:

 $numrow1=DB::table('teste') 
                    ->where('IdDesafiante','=',15) ||
                       ->where('IdDesafiante','=',16)
                            ->count();

second way:

  $numrow1=DB::table('teste') 
                        ->where('IdDesafiante','=',15 ||'IdDesafiante','=',16)
                                ->count();

2 answers

4


Use orWhere to make or and another where just to make and.

$numrow1=DB::table('teste') 
   ->where('IdDesafiante', '=', 15)
   ->orWhere('IdDesafiante', '=', 16)
   ->count();

Use the || in this case is not correct, is not semantic and has no logic. Laravel is object oriented.

1

If you need more "orWheres", or have a single data source being manipulated to mount the query you can also choose to whereIn:

$numrow1=DB::table('teste') 
   ->whereIn('IdDesafiante', array(15,16,17,18,19))
   ->count();

Browser other questions tagged

You are not signed in. Login or sign up in order to post.