laravel中外部定义whereIn的用法和where中使用in

laravel版本5.5

 外部定义whereIn的用法

if (!empty($id)) {
    $where[] = [
        function ($query) use ($id) {
            $query->whereIn('id', $id);
        },
    ];
}

where中使用in

如何在where中使用in,需要改底层的代码:当$operator == ‘in’ 的时候调用whereIn ,经测试是可以的(加入代码的位置,是放在if(is_array($column)))的后面。

 public function where($column, $operator = null, $value = null, $boolean = 'and')
    {
        // If the column is an array, we will assume it is an array of key-value pairs
        // and can add them each as a where clause. We will maintain the boolean we
        // received when the method was called and pass it into the nested where.
        if (is_array($column)) {
            return $this->addArrayOfWheres($column, $boolean);
        }
 
        if($operator === 'in'){
            return $this->whereIn($column,$value,$boolean);
        }

 

 备注:位置在vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php  版本的不同laravel 可能位置不同

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值