OrderBy not working in Laravel 5
I am using the following query. orderBy doesn't work in the following request. This request works on localhost, but it doesn't work on Online Server.
return DB::table('reports')
->leftJoin('sources', 'reports.report_source_id', '=', 'sources.id')
->select('*')
->orderBy('report_id', 'desc')
->take(10)
->get();
+3
abu abu
source
to share
3 answers
Try setting up an alias for each table and then using your required alias on orderBy
If there is in both tables report_id
, it won't know which one to use and will probably throw an error if you're looking for it.
return DB::table('reports as r')
->leftJoin('sources as s', 'r.report_source_id', '=', 's.id')
->select('*')
->orderBy('r.report_id', 'desc')
->take(10)
->get();
+2
RiggsFolly
source
to share
Try it. use "reports.report_id";
return DB::table('reports')
->leftJoin('sources', 'reports.report_source_id', '=', 'sources.id')
->select('*')
->orderBy('reports.report_id', 'desc')
->take(10)
->all();
+2
Deenadhayalan manoharan
source
to share
Try using reports.report_id like
return DB::table('reports')
->leftJoin('sources', 'reports.report_source_id', '=', 'sources.id')
->select('*')
->orderBy('reports.report_id', 'desc')
->take(10)
->get();
0
sujivasagam
source
to share