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);
Here's another way to do that.
$ids = array(9, 2, 16, 11, 8, 1, 18); $products = User::whereIn('id', $ids)->orderByRaw('FIELD(id, '.implode(',', $ids).')')->get();