How to sum one-to-one polymorphic relationship column through hasMany relationship in Laravel?
Owner model
public function capitals()
{
return $this->hasMany('App\Capital');
}
Capital model
public function transaction()
{
return $this->morphOne('App\Transaction', 'transacable');
}
Transaction model
public function transacable()
{
return $this->morphTo();
}
I want the owner to have-many transactions through capital, something like this:
Owner model
public function transactions()
{
return $this->hasManyThrough('App\Transaction', 'App\Capital', 'transacable_id')->where('transacable_type', 'App\Capital');
}
But I cannot get a relationship to work. and get this error.
Column not found: 1054 Unknown column 'capitals.transacable_id' in 'field list'