refactor: 处理文章发布时间为空情况
This commit is contained in:
@@ -16,6 +16,12 @@ class ArticleModel extends ArticleBaseModel
|
|||||||
// 软删除标记数据字段
|
// 软删除标记数据字段
|
||||||
protected $deleteTime = 'deleted_at';
|
protected $deleteTime = 'deleted_at';
|
||||||
|
|
||||||
|
// 写入前,处理发布时间为空情况
|
||||||
|
public static function onBeforeWrite(ArticleModel $article)
|
||||||
|
{
|
||||||
|
$article->release_time = empty($article->release_time) ? null : $article->release_time;
|
||||||
|
}
|
||||||
|
|
||||||
// 关联分类
|
// 关联分类
|
||||||
public function category()
|
public function category()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ class ArticleBaseModel extends BaseModel
|
|||||||
'image' => 'string',
|
'image' => 'string',
|
||||||
'desc' => 'string',
|
'desc' => 'string',
|
||||||
'recommend' => 'int',
|
'recommend' => 'int',
|
||||||
'release_time' => 'int',
|
'release_time' => 'datetime',
|
||||||
'sort' => 'int',
|
'sort' => 'int',
|
||||||
'link' => 'string',
|
'link' => 'string',
|
||||||
'content' => 'string',
|
'content' => 'string',
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ class CreateArticle extends Migrator
|
|||||||
->addColumn('seo_keywords', 'string', ['limit' => 255, 'null' => true, 'default' => null, 'comment' => 'SEO关键字'])
|
->addColumn('seo_keywords', 'string', ['limit' => 255, 'null' => true, 'default' => null, 'comment' => 'SEO关键字'])
|
||||||
->addColumn('seo_desc', 'string', ['limit' => 255, 'null' => true, 'default' => null, 'comment' => 'SEO描述'])
|
->addColumn('seo_desc', 'string', ['limit' => 255, 'null' => true, 'default' => null, 'comment' => 'SEO描述'])
|
||||||
->addColumn('enabled', 'boolean', ['null' => false, 'default' => 1, 'comment' => '是否启用:1是,-1否'])
|
->addColumn('enabled', 'boolean', ['null' => false, 'default' => 1, 'comment' => '是否启用:1是,-1否'])
|
||||||
->addColumn('release_time', 'datetime', ['null' => false, 'comment' => '发布时间'])
|
->addColumn('release_time', 'datetime', ['null' => true, 'default' => null, 'comment' => '发布时间'])
|
||||||
->addColumn('created_at', 'timestamp', ['null' => false, 'default' => 'CURRENT_TIMESTAMP', 'comment' => '创建时间'])
|
->addColumn('created_at', 'timestamp', ['null' => false, 'default' => 'CURRENT_TIMESTAMP', 'comment' => '创建时间'])
|
||||||
->addColumn('updated_at', 'timestamp', ['null' => false, 'default' => 'CURRENT_TIMESTAMP', 'update' => 'CURRENT_TIMESTAMP', 'comment' => '更新时间'])
|
->addColumn('updated_at', 'timestamp', ['null' => false, 'default' => 'CURRENT_TIMESTAMP', 'update' => 'CURRENT_TIMESTAMP', 'comment' => '更新时间'])
|
||||||
->addColumn('deleted_at', 'timestamp', ['null' => true, 'comment' => '删除时间'])
|
->addColumn('deleted_at', 'timestamp', ['null' => true, 'comment' => '删除时间'])
|
||||||
|
|||||||
Reference in New Issue
Block a user