我正在尝试显示按assigned_to
票数最多的受让人姓名。
$accesses = Access::where('state','=','Assigned');
$all = Report::where('state', '=', 'Assigned')
->union($accesses)
->orderBy('count(assigned_to)') //THIS IS WRONG
->get();
最佳答案
你必须使用 DB::raw
来获取它
$all = Report::where('state', '=', 'Assigned')
->select(DB::raw('count(reports.assigned_to) as assigned_to'))
->union($accesses)
->orderBy('assigned_to','DESC')
->get();
关于php - 拉维尔 5.4 : How to order by count(column) in eloquent?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45408158/