如何在 laravel 5 中组合括号内的查询条件
How to combile query conditions inside bracket in laravel 5
在 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` != ?")
感谢您的帮助。
我会尝试 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 != '')
在 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` != ?")
感谢您的帮助。
我会尝试 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 != '')