I want to sort the records using orderBy method in desc order on the created_at field. But my code doesn't take my orderBy method. Don't know what is the problem. Given below is my code.
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;
}
Can anybody help me?