在laravel 5中,我使用下面的查询构建器
$user_social = DB::table('users')
->where('email','=',$credentials['email'])
->where('facebook', '!=', '')
->orWhere('google', '!=', '')
->get(['facebook','google']);
我正在收到由查询构建器生成的查询
"select * from `users` where `email` = ? and `facebook` != ? or `google` != ?"
进行此类查询需要进行哪些更改。
"select * from `users` where `email` = ? and (`facebook` != ? or `google` != ?")
感谢您的帮助。
答案 0 :(得分:0)
我会尝试类似this的内容:
$user_social = DB::table('users')
->where('email', '=', $credentials['email'])
->orWhere(function($query)
{
$query->where('facebook', '!=', '')
->where('google', '!=', '');
})
->get(['facebook','google']);
这会生成一个像这样的查询
select * from users where email = 'email' or (facebook != '' and google != '')