1
This commit is contained in:
40
app/common/model/Articles.php
Normal file
40
app/common/model/Articles.php
Normal file
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
class Articles extends TimeModel
|
||||
{
|
||||
protected array $rule = [
|
||||
'title' => 'require|max:50',
|
||||
'cate_id' => 'require|integer|gt:0',
|
||||
'cover' => 'max:255',
|
||||
'summary' => 'max:255',
|
||||
'author' => 'max:50',
|
||||
'sort' => 'integer|egt:0',
|
||||
'status' => 'in:0,1'
|
||||
];
|
||||
protected array $message = [
|
||||
'title.require' => '文章标题不能为空',
|
||||
'title.max' => '文章标题最多50个字符',
|
||||
'cate_id.require' => '分类ID不能为空',
|
||||
'cate_id.integer' => '分类ID必须为整数',
|
||||
'cate_id.gt' => '分类ID必须大于0',
|
||||
'cover.max' => '封面路径最多255个字符',
|
||||
'summary.max' => '简介最多255个字符',
|
||||
'author.max' => '作者最多50个字符',
|
||||
'sort.integer' => '排序必须为整数',
|
||||
'sort.egt' => '排序不能小于0',
|
||||
'status.in' => '状态值错误'
|
||||
];
|
||||
|
||||
public function cate()
|
||||
{
|
||||
return $this->belongsTo(ArticleCates::class, 'cate_id');
|
||||
}
|
||||
|
||||
|
||||
public function getCateNameAttr($value, $data)
|
||||
{
|
||||
return $this->cate ? $this->cate->title : '';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user