update cms

This commit is contained in:
JaguarJack 2021-05-31 08:43:40 +08:00
parent 44f5bf345b
commit 72bf97579b
2 changed files with 59 additions and 1 deletions

View File

@ -0,0 +1,47 @@
<?php
// +----------------------------------------------------------------------
// | CatchAdmin [Just Like ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~{$year} http://catchadmin.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
// +----------------------------------------------------------------------
// | Author: JaguarJack [ njphper@gmail.com ]
// +----------------------------------------------------------------------
use think\migration\Migrator;
use think\migration\db\Column;
class UpdateArticleColumns extends Migrator
{
/**
* Change Method.
*
* Write your reversible migrations using this method.
*
* More information on writing migrations is available here:
* http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
*
* The following commands can be used in this method and Phinx will
* automatically reverse them when rolling back:
*
* createTable
* renameTable
* addColumn
* renameColumn
* addIndex
* addForeignKey
*
* Remember to call "create()" or "update()" and NOT "save()" when working
* with the Table class.
*/
public function change()
{
if ($this->hasTable('cms_articles')) {
$table = $this->table('cms_articles');
$table->renameColumn('comments', 'comment_num')
->update();
}
}
}

View File

@ -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');
}
}