Is it possible to use the following orderByRaw(). This orderByRaw() is returning the products in the same order as the whereIn(). Right now it's only the results in the orderByRaw order and not the orderBy().
Is it possibile to combine these:
$ids; $placeholders = implode(',',array_fill(0, count($ids), '?')); Product::whereIn('id', $ids)->orderByRaw("field(id,{$placeholders})" ,$ids)->orderBy('views', 'des')->orderBy('created_at', 'des')->get();
Edit: This is the SQL I get when I do toSql(). Why isn't this working?
SELECT * FROM `products` WHERE `id` IN ( ?, ?, ?, ?, ? ) ORDER BY Field(id, ?, ?, ?, ?, ?), `views` DESC, `created_at` DESC