orderBy在Laravel 5中不起作用 [英] orderBy is not working in Laravel 5
本文介绍了orderBy在Laravel 5中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用以下查询. orderBy 在下面的查询中不起作用.此查询在localhost中运行,但在Online Server中不运行.
I am using the below query. orderBy is not working in below query. This query is working in localhost but it is not working in Online Server.
return DB::table('reports')
->leftJoin('sources', 'reports.report_source_id', '=', 'sources.id')
->select('*')
->orderBy('report_id', 'desc')
->take(10)
->get();
推荐答案
尝试为每个表设置一个别名,然后在orderBy上使用所需的别名
Try setting an alias for each table and then using the required alias on the orderBy
如果两个表中都有一个report_id
,它将不知道要使用哪个,并且在查找时可能会引发错误.
If there is a report_id
in both tables it will not know which one to use and is probably throwing an error if you look 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();
这篇关于orderBy在Laravel 5中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文