微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

PHP-OrderBy在Laravel 5中不起作用

我正在使用以下查询. orderBy在下面的查询中不起作用.此查询在localhost中运行,但在Online Server中不运行.

return DB::table('reports')
        ->leftJoin('sources', 'reports.report_source_id', '=', 'sources.id')
        ->select('*')
        ->orderBy('report_id', 'desc')
        ->take(10)
        ->get();

解决方法:

尝试为每个表设置一个别名,然后在orderBy上使用所需的别名

如果两个表中都有一个report_id,它将不知道要使用哪个,并且如果您查找它,可能会引发错误.

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();

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐