Laravel - Use OR within where

2

I am using the ->cont command to count the return number, and for this I put a condition using ->WHERE , but when I try to put a || in the condition it will look for the answer. p>

code 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 mode:

  $numrow1=DB::table('teste') 
                        ->where('IdDesafiante','=',15 ||'IdDesafiante','=',16)
                                ->count();
    
asked by anonymous 12.07.2018 / 15:34

2 answers

4

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

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

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

    
12.07.2018 / 15:47
1

If you need more "orWheres", or you have a single data source being manipulated to perform the query assembly, you can also opt for whereIn :

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