I have a list of ids which are id after a collection is sorted, e.g:
$orderedIds = "2,18,4,1,17,5,6,16,15,14,13,11,12,10,9,8,7,3"
and I want to pick them out with whereRaw
like this:
$result = Collection::whereRaw("FIELD(id, ".$orderedIds." )");
but the result is automatically sorted by id, which mean the collection output are literally the original collection:
[
{
"id": 1,
...
}, {
"id": 2,
...
}, {
"id": 3,
...
}
]
Any option with whereRaw
, or any other way around for me to achieve the sorted collection?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire