【发布时间】:2020-08-22 21:43:51
【问题描述】:
这里有一些关于表格的信息
User table
-id
-name
UserProduct table
-id
-user_id
-product_id
Product table
-id
-name
Contribution
-id
-user_product_id
-contribution
用户模型
public function products()
{
return $this->belongsToMany('App\Product');
}
产品型号
public function users()
{
return $this->belongsToMany('App\User');
}
UserProduct 透视模型
use Illuminate\Database\Eloquent\Relations\Pivot;
class UserProduct extends Pivot
{
public function contribution()
{
return $this->hasMany('App\Contribution');
}
}
我尝试auth()->user()->products()->first()->pivot->contribution(),但它给出了一些错误。
调用未定义的方法 Illuminate\Database\Eloquent\Relations\Pivot::contribution()
【问题讨论】: