我有两个课程:public void Main()
{
const int a = 1;
const int b = 3;
var t1 = Task.Run(() => new
{
c = a + 5
}
);
var t2 = t1.ContinueWith(t =>
new
{
c = t.Result.c,
d = b + 3
}
);
var t3 = t2.ContinueWith(t =>
t.Result.c + t.Result.d
);
var result = t3.Result;
}
和相关的Share
我在EquityGrant
EquityGrant
但是现在我需要返回public function share() //relationship
{
return $this->belongsTo(Share::class, 'share_id');
}
public function capitalCommitted() //my math function
{
return $this->share_price * $this->shares_amount;
}
Share
类capitalCommitted()
函数的总和,这里我被卡住了。
我的Share
课程:
public function grants() //relationship
{
return $this->hasMany(EquityGrant::class);
}
public function totalIssued() //sum, works good
{
return $this->grants->sum('shares_amount');
}
public function totalCommitted() //Stuck here
{
//need help here, Must be like this: array_sum($this->grants->capitalCommitted());
}
答案 0 :(得分:2)
使用此:
public function getCapitalCommittedAttribute()
{
return $this->share_price * $this->shares_amount;
}
public function totalCommitted()
{
return $this->grants->sum('capitalCommitted');
}