我有一个多态关系,注释:(id,文本,commentable_id,commentable_type),图像:(id,标题)和视频:(id,标题)。
视频表与问题表有很多关系。
我设法恢复了评论及其与视频之间的关系,但是我无法恢复问题的标题,从评论表传递到视频表之后,然后是事物表。
在我的要求下。
class Comment extends Model
{
public function commentable()
{
return $this->morphTo();
}
}
class Video extends Model
{
public function comments()
{
return $this->morphOne(Comment::class, 'commentable');
}
public function matters()
{
return $this->belongsToMany(Matter::class, 'videos_matters');
}
}
class Matter extends Model
{
public function videos()
{
return $this->belongsToMany(Video::class, 'videos_matters');
}
}
Request :
$comments = Comment::with('created_by')
->with('commentable.matters')
->whereDate('created_at', '=', date('Y-m-d'))
->get();
class Video Matter Model
是什么?您是要声明class Matter extends Model
吗?