【Laravel】DB查询 where 例子记录

时间:2020-11-02 10:13:57   收藏:0   阅读:29

在数据查询时候,多条件查询,使用场景

//单个值
$data_where[‘id‘] = 1

// in 条件 写法一
$ids = [1,2,3,4,5];
$data_where[] = [DB::raw("字段名 in ({$ids})"),‘1‘];
//in条件写法二
$data_where[] = [‘in‘=>[‘id‘=>$ids]];

$condition[] =[‘id‘,‘in‘,$ids]; // 这是错误的写法
// Illuminate\Database\Query\Builder关于operators定义中,并没有in
public $operators = [
    ‘=‘, ‘<‘, ‘>‘, ‘<=‘, ‘>=‘, ‘<>‘, ‘!=‘,
    ‘like‘, ‘like binary‘, ‘not like‘, ‘between‘, ‘ilike‘,
    ‘&‘, ‘|‘, ‘^‘, ‘<<‘, ‘>>‘,
    ‘rlike‘, ‘regexp‘, ‘not regexp‘,
    ‘~‘, ‘~*‘, ‘!~‘, ‘!~*‘, ‘similar to‘,
    ‘not similar to‘, ‘not ilike‘, ‘~~*‘, ‘!~~*‘,
];


评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!