能把whereDoesntHave放在数组条件里,实现查询吗

Laravel 5.8.38
laravel-admin 1.7.6
PHP 版本:7.3.1

想用把查询条件放在数组里进行查询,如下

$where=[
['id','>',180],
['source','=','12']
['created_at','>=','2023-01-01']
];
$query->where($where);

其中有个查询要实现副表的某个字段值为空(副表字段为空, 也就是说,副表记录不存在,或对应字段为0),我是这样写的

 $where[]= [function ($q) use($join,$column, $v ){
                $q->whereDoesntHave($join)
                    ->orWhere(function ($q)use($join,$column){
                        $q->whereHas($join,function ($q)use($column){
                            $q->whereNUll($column)->orWhere($column,0);
                        });
                    })
                ;
            }];

但会报错

select count(*) as aggregate from `customer` where  (`doesnt_have` = ext or (`has` = ext))) and customer.is_del= 0 group by `addcustomer`.`id`)

应该要怎么实现呢?

《L01 基础入门》
我们将带你从零开发一个项目并部署到线上,本课程教授 Web 开发中专业、实用的技能,如 Git 工作流、Laravel Mix 前端工作流等。
《G01 Go 实战入门》
从零开始带你一步步开发一个 Go 博客项目,让你在最短的时间内学会使用 Go 进行编码。项目结构很大程度上参考了 Laravel。
讨论数量: 1

现在的处理是,如果是这种查询, 不放在数组里,

$where=[
   ['id','>',180],
   ['source','=','12']
   ['created_at','>=','2023-01-01']
];
$query->where($where)
     ->where(function ($q) use($join,$column, $v ){
         $q->whereDoesntHave($join)
             ->orWhere(function ($q)use($join,$column){
                    $q->whereHas($join,function ($q)use($column){
                        $q->whereNUll($column)->orWhere($column,0);
                   });
               })
            ;
       });
1年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!