Skip to content
Advertisement

How to write Laravel orderBy query?

i tried this in laravel,but its not worked.

$doctor_daily=ReportDoctorCompanyDailyTestModal::select('test_id',DB::raw('SUM(test_price) as num'))
                                                       ->join('testing_types','report_doctor_company_daily_test.test_id','=','testing_types.id')
                                                       ->join('doctor','doctor.id','=','report_doctor_company_daily_test.doctor_id')
                                                       ->groupBy('test_id')
                                                       ->get();

How to write this MySQL query in Laravel 5.7?

SELECT
    report_doctor_company_daily_test.test_id,
    testing_types.testing_name,
    doctor.first_name,
    doctor.last_name,
    SUM( report_doctor_company_daily_test.test_price ) 
FROM
    testing_types
    INNER JOIN report_doctor_company_daily_test ON testing_types.id = report_doctor_company_daily_test.test_id
    INNER JOIN doctor ON report_doctor_company_daily_test.doctor_id = doctor.id 
GROUP BY
    testing_types.id

Advertisement

Answer

use can use ->orderBy(); statment.

as example;

$doctor_daily=ReportDoctorCompanyDailyTestModal()->orderBy()->get();

Then you can get data by ascending order. if you want descending order, can use

->orderBy('id','DESC');
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement