diff --git a/catch/cms/database/migrations/20210528032001_update_article_columns.php b/catch/cms/database/migrations/20210528032001_update_article_columns.php new file mode 100644 index 0000000..13f5a6c --- /dev/null +++ b/catch/cms/database/migrations/20210528032001_update_article_columns.php @@ -0,0 +1,47 @@ +hasTable('cms_articles')) { + $table = $this->table('cms_articles'); + + $table->renameColumn('comments', 'comment_num') + ->update(); + } + } +} diff --git a/catch/cms/model/Articles.php b/catch/cms/model/Articles.php index 3196195..d4c13fc 100644 --- a/catch/cms/model/Articles.php +++ b/catch/cms/model/Articles.php @@ -75,7 +75,7 @@ class Articles extends BaseModel // 喜欢 'likes', // 评论数 - 'comments', + 'comment_num', // 1 置顶 2 非置顶 'is_top', // 1 推荐 2 不推荐 @@ -182,4 +182,15 @@ class Articles extends BaseModel { return $this->tag()->attach($ids); } + + /** + * 文章评论 + * + * @time 2021年05月27日 + * @return \think\model\relation\HasMany + */ + public function comments(): \think\model\relation\HasMany + { + return $this->hasMany(Comments::class, 'article_id', 'id'); + } } \ No newline at end of file