Laravel 模型关联 hasManyThrough 反向关联怎么配置

现在有3个数据表

schools:
    id
    name

grades:
    id
    name
    school_id

students:
    id
    name
    grade_id

我在School 模型定义了一个远程一对多的关系获取学校的学生

public function students()
    {
        return $this->hasManyThrough(
            Student::class,
            Grade::class,
                'school_id',
                'grade_id',
                'id',
                'id'
        );
    }

现在有个需求想在 Student 直接获取 School,
通过在 Student belongsTo(Grade::class)
在 Grade belongsTo(School::class)
这样 $student->grade->school 获取没有问题
我现在想直接 $student->school 有什么优雅的办法
是否类似这样去获取?

public fuction school()
{
  return $this->grade()->school(); 
}
《L02 从零构建论坛系统》
以构建论坛项目 LaraBBS 为线索,展开对 Laravel 框架的全面学习。应用程序架构思路贴近 Laravel 框架的设计哲学。
《G01 Go 实战入门》
从零开始带你一步步开发一个 Go 博客项目,让你在最短的时间内学会使用 Go 进行编码。项目结构很大程度上参考了 Laravel。
讨论数量: 0
(= ̄ω ̄=)··· 暂无内容!

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!