问题描述
我想问一下如何通过多个列中的一些进行排序。 在项目表中,我有3列“ is_recommended”,“ is_popular”,“ is_new”(标签) 我想按每一行的标签总数进行排序。例如
id=1 has is_recommended=1,is_popular=1,is_new=1 => attributes = 3
id=2 has is_recommended=0,is_popular=0,is_new=1 => attributes = 1
id=3 has is_recommended=1,is_new=1 => attributes = 2
因此,订单将为id2,id3,id1。 我的代码:
$items = Item::addSelect(['attributes' => Item::selectRaw('`is_recommended` + `is_popular` + `is_new` as attributes')])
->sortable()
->orderBy('id','DESC')->with('item_category','restaurant')->paginate(20);
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)