php - Lumen AND OR conditions in Where clause -
i trying run following query in lumen framework:
select * user (username = $username or email = $username) , password = $password , flag = 1;
my lumen code:
$login = user::where('pass', '=', md5($pass)) ->where('flag', '=', $flag) ->where('username', '=', $username) ->orwhere('email', '=', $username)->first();
somehow code return true , bypass login. wrong in query?
when remove orwhere
query works perfect username.
if want group 2 conditions (username , email) single condition (surrounded parenthesis), have this:
user::where('pass', '=', md5($pass)) ->where('flag', '=', $flag) ->where(function ($query) use ($username) { $query->where('username', '=', $username) ->orwhere('email', '=', $username); })->first();
here documentation on advanced conditions laravel query builder (which lumen uses).
Comments
Post a Comment