如何使用if else在两个orderBy之间在雄辩的laravel
->orderBy('created_at', 'DESC') ->join('hr_applicants', 'hr_applications.hr_applicant_id', '=', 'hr_applicants.id') ->orderBy('hr_applicants.name', 'ASC')
m1m5dgzv1#
不太清楚你是怎么做的,但你可能会这样做:
$query = .... /*your query code here*/ ->orderBy('created_at', 'DESC') ->join('hr_applicants', 'hr_applications.hr_applicant_id', '=', 'hr_applicants.id') ->orderBy('hr_applicants.name', 'ASC'); if ($condition1) { $query = $query->orderBy('table.column', 'ASC'); } else { $query = $query->orderBy('table.column2', 'DESC'); } $result = $query->get();
1条答案
按热度按时间m1m5dgzv1#
不太清楚你是怎么做的,但你可能会这样做: