Laravel: order by where in
问题 I am using SphinxSearch to query some contents and have the ids of my objects that I want to query with MySQL. The array of my ids are sorted depending on their rank Sphinx gives. Thus, I would like to make a MySQL like so: SELECT * FROM table WHERE id IN (1,17,2) ORDER BY FIELD(id,1,17,2) I know I can do: Table::whereIn('id', $ids)->get(); But I can't get the order I had. How can I do that in a proper way with Laravel ? 回答1: Using the solution found on http://laravelsnippets.com/snippets/get