【问题标题】:Eloquent ORM hasManyThrough for more than 1 segmentEloquent ORM hasManyThrough 超过 1 段
【发布时间】:2014-10-31 08:02:33
【问题描述】:

Eloquent ORM hasManyThrough 让我可以接触到 1 段以外的对象。 有没有一种简单的方法来获取超过 1 段以外的对象?

例如我有这样的对象:

帐户 民意调查 - 帐户ID 受访者 - 调查ID 内容 - respondent_id

如何获取给定帐户对象的内容对象?

【问题讨论】:

  • 没有内置方法。

标签: laravel orm eloquent relationship


【解决方案1】:

我不知道有什么方法可以使用 hasManyThrough() 访问 2 个分段,但如果您已设置所有关系,您可以急切地加载它们。

$accounts = Account::with('surveys.respondents.content')->get();

【讨论】:

    猜你喜欢
    • 2016-09-24
    • 2016-08-21
    • 2022-06-10
    • 2014-08-14
    • 2020-03-07
    • 2015-07-13
    • 2020-10-14
    • 2020-02-02
    • 1970-01-01
    相关资源
    最近更新 更多