1:order
V5.0.17+
版本开始,当你的order排序中使用了SQL函数的时候,请使用orderRaw
方法替代order
,例如:
/**
* 获取文章列表
* @return \think\Paginator
* @throws \think\exception\DbException
*/
public function getList()
{
try{
$info = $this->with(['image', 'category'])
->where('is_delete', '=', 0)
->orderRaw("field(article_status,1,2)") //article_status字段等于 1 的排在前面,等于 2 的排在后面
->order(['article_sort' => 'asc'])
->paginate(10, false, [
'query' => request()->request()
]);
} catch (\Exception $e) {
$this->error = $e->getMessage();
return false;
}
return $info;
}