我可以在Laravel中使用orderBy
方法,如下所示:
$posts = Post::orderBy('id', 'DESC')->get();
好的,CASE
条款中有ORDER BY
的时候怎么办?像这样:
ORDER BY
CASE
WHEN id.PinRequestCount <> 0 THEN 5
WHEN id.HighCallAlertCount <> 0 THEN 4
WHEN id.HighAlertCount <> 0 THEN 3
WHEN id.MediumCallAlertCount <> 0 THEN 2
WHEN id.MediumAlertCount <> 0 THEN 1
END desc,
我怎样才能在Laravel中写这个^?
答案 0 :(得分:5)
试试这个:
->orderByRaw(
"CASE WHEN <CONDITION> THEN < > ELSE < > END DESC"
)
答案 1 :(得分:1)
你要使用[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public void GetSearchCritetrion(object selectedItem)
{
var json = new JavaScriptSerializer();
var data = json.Deserialize<Dictionary<string, Dictionary<string, string>>[]>(selectedItem.ToString());
}
,正如sagi也提到的那样。
raw