这里有一些关于表格的信息
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');
}
用户产品枢轴模型
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()
POPMUISE
MM们