[英]How do I prevent mobile devices from automatically downloading a PDF on my website?
[英]How to prevent whereRaw from automatically sort my collection?
我有一個 id 列表,它們是排序后的集合的 id,例如:
$orderedIds = "2,18,4,1,17,5,6,16,15,14,13,11,12,10,9,8,7,3"
我想像這樣用whereRaw
來挑選它們:
$result = Collection::whereRaw("FIELD(id, ".$orderedIds." )");
但結果會自動按 id 排序,這意味着集合 output 從字面上看就是原始集合:
[
{
"id": 1,
...
}, {
"id": 2,
...
}, {
"id": 3,
...
}
]
whereRaw
的任何選項,或任何其他方式讓我實現排序集合?
嘗試這個
Collection::whereIn('id',$orderedId)->orderByRaw(DB::raw("FIELD(id, $orderedId)"))->get();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.