我有一个雄辩的查询
Role::where("(company_id = Auth::user()->company_id or name = 'admin')and id in(2,3)")->pluck('name');
根据我的口才,sql应该是
select `name` from `roles` where ( company_id = 1 or name = admin ) and id IN (2, 3) and `roles`.`deleted_at` is null
但是它执行为
select `name` from `roles` where ( company_id = 1 or name = admin ) and id IN (2, 3) is null and `roles`.`deleted_at` is null
有人可以帮我总结一下为什么在查询中应用了额外的is null
条件吗?
注意:我正在使用软删除
答案 0 :(得分:0)
您应该使用whereRaw而不是where
Role::whereRaw("(company_id = Auth::user()->company_id or name = 'admin')and id in(2,3)")->pluck('name');