1
0
Files
helper/application/common/model/Article.php
2020-08-06 14:58:51 +08:00

59 lines
1.5 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
// +------------------------------------------------+
// |http://www.cjango.com |
// +------------------------------------------------+
// | 修复BUG不是一朝一夕的事情等我喝醉了再说吧 |
// +------------------------------------------------+
// | Author: 小陈叔叔 <Jason.Chen> |
// +------------------------------------------------+
namespace app\common\model;
class Article extends _Init
{
/**
* 模型初始化【事件注册】
*/
protected static function init()
{
self::beforeInsert(function ($data) {
$data->status = 1;
});
}
/**
* 获取封面地址
* @param [type] $value 封面id
* @param [type] $data 文章数据
* @return [type] 图片地址
*/
public function getCoverAttr($value, $data)
{
return Storage::where('id', $data['storage_id'])->find();
}
/**
* 获取封面地址
* @param [type] $value 封面id
* @param [type] $data 文章数据
* @return [type] 图片地址
*/
public function getCreateTimeAttr($value, $data)
{
return date('Y-m-d', $value);
}
/**
* 获取关联的分类
* @return [type] [description]
*/
public function category()
{
return $this->hasOne('Category', 'id', 'category_id');
}
public function user()
{
return $this->belongsTo('MemberInfo', 'uid', 'uid');
}
}