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 可能位置不同