$ids = [4,3,1,2];
$result = DB::table('products')->where('status',1)->whereIn('id',$ids)->paginate(10);
所以这里的id [4,3,1,2]的顺序我想要分页数据
答案 0 :(得分:0)
最后我得到了答案。
$ids = [4,3,1,2];
$ids_ordered = implode(',', $ids);
$result = DB::table('products')->where('status',1)->whereIn('id',$ids)->orderByRaw(DB::raw("FIELD(id, $ids_ordered)"))->paginate(10);