当前位置: 动力学知识库 > 问答 > 编程问答 >

I want to use withPivot with morphMany in Laravel 5.2 and that gives me an error, what can I use instead for polymorphic relationship

问题描述:

I have a table votes that looks like this:

id

user_id

votable_id

votable_type

status

I need to be able to set the status so I thought this would work:

class Comment extends Model

{

public function votes(){

return $this->morphMany(Vote::class, 'votable')->withPivot('status');

}

}

However that gives this error:

BadMethodCallException with message 'Call to undefined method Illuminate\Database\Query\Builder::withPivot()'

分享给朋友:
您可能感兴趣的文章:
随机阅读: