【发布时间】:2021-11-05 03:58:35
【问题描述】:
我从getReward1 和getReward2 得到不同的结果:
型号:
class User extends Authenticatable
{
public function Products()
{
return $this->hasMany('App\Product', 'user_id');
}
public function getReward1()
{
return $this
->Products
->where('reward', '>', 0)
->where('status', 0)
->sum('reward'); // sum = 7,690,000
}
public function getReward2()
{
return $this
->Products()
->where('reward', '>', 0)
->where('status', 0)
->sum('reward'); // sum = 7,470,000
}
}
getReward1 返回 7,690,000 和 getReward2 返回 7,470,000(两个不同的值)
$this->Products 和 $this->Products() 有什么区别?
【问题讨论】: