我有一個類似下面的評論系統。用戶可以評論文章,圖片和帖子。一切正常。但除此之外,我想添加一個用戶可以評論網站本身的部分,就像一般評論一樣。我想將其與現有評論系統集成。但是,自然地,我沒有可以添加關係的網站本身的表格或模型。什麼是一個好的方法去?如何在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();
}
}
如果你有可能有一個'用戶'表,那麼可能是它的時間來添加評論關係到'用戶'模型?即成爲評論的一部分也只是想辦法...... –