$room = DB::table('room')
->where(function($query) use($contList){
foreach ($contList as $k=>$v){
//拼接查询条件
$query->orwhere(function ($query) use($v) {
$query->where('id', '=', $v['room_id'])->where('hotel_id', '=', $v['hotel_id']);
});
}
})
->select(['id','hotel_id','room_number'])
->get()->keyBy('id')
->toArray();
以上代码解析sql语句如下
"select `id`, `hotel_id`, `room_number` from `mm_room` where ((`id` = ? and `hotel_id` = ?) or (`id` = ? and `hotel_id` = ?) or (`id` = ? and `hotel_id` = ?))"
注:keyBY() 意为:以id为键值输出 必须写到get()后面 不然会报错