【问题标题】:Laravel deep relationsLaravel 深层关系
【发布时间】:2015-07-19 18:59:20
【问题描述】:

我在建立一些深入的关系时遇到了一些麻烦。 基本架构:

一个事件可以有多个班次。

一个班次有多个要求。

一个需求有很多请求。

在我的事件类中,我有以下代码

 public function shifts()
{
    return $this->hasMany('App\Models\Shift');
}

public function requirements(){
    return $this->hasManyThrough('App\Models\Requirement', 'App\Models\Shift');
}

public function sollicitations(){
    return ???
}

此代码按预期工作,不会引发任何错误。

我想在 Event 类中添加一个新方法“请求”。 此方法应返回事件所有班次的所有要求的所有征集。

我该怎么走

$this->requirements()-> ???

以便我得到所有的邀请?

编辑 当我调用“$this->requirements”时,我得到了所有需求的集合。 我也想要同样的东西,只是为了征集。

【问题讨论】:

    标签: eloquent laravel-5


    【解决方案1】:
    public function sollicitations($eventID){
        return $this->hasMany('your sollicitations class')->with('requirements')->find($eventID);
    }
    

    请根据您的要求更改您的关系。和类名也有关系。

    【讨论】:

    • 返回数据库中的所有事件
    • 是的,仅附加依赖于它的数据。你想要什么?
    • 我想收集特定活动的所有征集
    • 对不起,它不起作用,它仍然返回事件集合,而不是请求之一
    • 请再试一次。很抱歉我之前没有问过你问题。
    猜你喜欢
    • 2018-05-21
    • 2021-12-17
    • 1970-01-01
    • 1970-01-01
    • 2021-12-06
    • 2018-06-06
    • 2016-03-05
    • 2015-10-16
    • 2021-10-23
    相关资源
    最近更新 更多