雄辩的渴望加载订单 [英] Eloquent eager load Order by

查看:120
本文介绍了雄辩的渴望加载订单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有雄辩的查询问题。我使用热心加载(一对一关系)来获得学生使用考试,使用下面的代码。

I have problem with eloquent query. I am using eager loading (one to one Relationship) to get 'student' With the 'exam', Using the code below.

Student::with('exam')->orderBy('exam.result', 'DESC')->get()

我想通过考试中的结果列排序接收的行。我正在使用

And i want to order received rows by the 'result' column in 'exam'. I am using

->orderBy('exam.result', 'DESC')

但它不工作。任何想法如何做?

But it is not working. Any ideas how to do it ?

推荐答案

尝试这个:

Student::with(array('exam' => function($query) {
        $query->orderBy('result', 'DESC');
    }))
    ->get();

这篇关于雄辩的渴望加载订单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆