SELECT * FROM `users` WHERE (email=$email or phone=$phone) AND is_deleted=0 AND role_id!=2 AND role_id!=3
如何编写此代码?
答案 0 :(得分:0)
如果您有User Model
,可以编码:
User::where('is_deleted', 0)->where('role_id', '<>', 2)->where('role_id', '<>', 3)
->where(function ($query) use ($email, $phone) {
return $query->where('email', $email)
->orWhere('phone', $phone)
})->get();
或使用数据库查询:
DB::table('users')->select('*')
->whereRaw(DB::raw("(email=$email or phone=$phone) AND is_deleted=0 AND role_id<>2 AND role_id<>3"))->get();