我有一个类似下面的评论系统。用户可以评论文章,图片和帖子。一切正常。但除此之外,我想添加一个用户可以评论网站本身的部分,就像一般评论一样。我想将其与现有评论系统集成。但是,自然地,我没有可以添加关系的网站本身的表格或模型。什么是一个好的方法去?如何在laravel的现有评论系统中添加/集成一般网站评论?
表是这样的:
articles
id - integer
title - string
body - text
posts
id - integer
title - string
body - text
images
id - integer
title - integer
path - text
comments
id - integer
comment - text
commentable - integer
commentable_type - string
和模式是这样的:
class Post extends Model
{
public function comments()
{
return $this->morphMany(Comment::class, 'commentable');
}
}
class Images extends Model
{
public function comments()
{
return $this->morphMany(Comment::class, 'commentable');
}
}
class Article extends Model
{
public function comments()
{
return $this->morphMany(Comment::class, 'commentable');
}
}
class Comment extends Model
{
public function commentable()
{
return $this->morphTo();
}
}
如果你有可能有一个'用户'表,那么可能是它的时间来添加评论关系到'用户'模型?即成为评论的一部分也只是想办法...... –