3
$ids = [4,3,1,2];
$result = DB::table('products')->where('status',1)->whereIn('id',$ids)->paginate(10);

So here the order of ids [4,3,1,2] in this same order i want paginate data

Akash Kumar Verma
  • 3,185
  • 2
  • 16
  • 32

1 Answers1

1

Finally i got answer.

$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);
Wai Ha Lee
  • 8,598
  • 83
  • 57
  • 92
Akash Kumar Verma
  • 3,185
  • 2
  • 16
  • 32