Monday, March 13, 2017

Laravel Where and OrWhere

I am trying to figure out how to create the following query in eloquent:

SELECT * 
FROM  `pvp_battles` 
WHERE (player1_id = 2 || player2_id =2) && winner !=2

2 is the player id. This is what I did:

$profile->loses = PvpBattle::where('player1_id',$profile->id)
        ->orWhere('player2_id',$profile->id)
        ->where('winner','!=',$profile->id)->count();

Sadly it shows that the count is 49 while it's 25. What's wrong?



via TheUnreal

Advertisement