如何通过Laravel中的hasMany关系求和一对一的多态关系列?

How to sum one-to-one polymorphic relationship column through hasMany relationship in Laravel?

如何通过Laravel中的hasMany关系求和一对一的多态关系列?

所有者模型

public function capitals()
{
    return $this->hasMany('App\Capital');
}

资本模型

public function transaction()
{
    return $this->morphOne('App\Transaction', 'transacable');
}

交易模式

public function transacable()
{
    return $this->morphTo();
}

我希望所有者通过资本进行多笔交易,例如:

所有者模型

public function transactions()
{
   return $this->hasManyThrough('App\Transaction', 'App\Capital', 'transacable_id')->where('transacable_type', 'App\Capital');
}

但我无法找到工作关系。并得到这个错误。

Column not found: 1054 Unknown column 'capitals.transacable_id' in 'field list'

transacable_id放在正确的位置:

public function transactions()
{
   return $this->hasManyThrough(
            'App\Transaction',
            'App\Capital',
            'owner_id', // Foreign key on capitals table...
            'transacable_id', // Foreign key on transactions table...
            'id', // Local key on owners table...
            'id' // Local key on capitals table...
        )->where('transacable_type', 'App\Capital');
}