我想要使用orderBy方法在created_at字段上按desc顺序排序记录。但我的代码并不需要我的orderBy方法。不知道是什么问题。以下是我的代码。orderBy方法在laravel 5
public function getLastControll()
{
$result = Order::select(DB::Raw("(SELECT sum(hour_logging.normal_hours+hour_logging.normal_50pst+hour_logging.normal_100pst)FROM hour_logging WHERE hour_logging.ordre_id=ordre.id) AS total_hours"))
->join('hour_logging','hour_logging.ordre_id','=','ordre.id','left')
->addSelect('ordre.*', (DB::raw("(select max(created_at) from ordre where ordre.id=hour_logging.ordre_id order by created_at desc) as sub")))
->where('ordre.status', '>', '003')
->where('ordre.main_order', 1)
->groupBy('customer_id')
->get();
return $result;
}
有人能帮助我吗?
'orderBy'甚至没有在代码中使用! –
尝试 - > orderBy('created_at','desc'); –
因为我使用groupBy我无法在这里使用orderBy。所以你可以在这里找到它(DB :: raw(“(从ordre选择max(created_at),其中ordre.id = hour_logging.ordre_id order by created_at desc)as sub)”) – cathy123