I have an array of product ids against which I need to retrieve the model collection. The array is something like this:
$ids = array(9, 2, 16, 11, 8, 1, 18);
Use Field() function of mysql (If you are using mysql database) with DB::raw() of laravel something like
Field()
DB::raw()
$products = Product::whereIn('id', $ids) ->orderBy(DB::raw("FIELD(id,".join(',',$ids).")")) ->get();
Field() returns the index position of a comma-delimited list