| // +------------------------------------------------+ namespace app\common\model; class Content 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'])->value('path'); } /** * 获取关联的分类 * @return [type] [description] */ public function category() { return $this->hasOne('Category', 'id', 'category_id'); } }