| // +------------------------------------------------+ namespace app\common\model; class Experience extends _Init { /** * 模型初始化【事件注册】 */ protected static function init() { self::beforeInsert(function ($data) { $data->status = 1; }); } public function user() { return $this->belongsTo('MemberInfo', 'uid', 'uid'); } public function comment() { return $this->hasMany('Experience', 'pid', 'id')->order('id asc'); } public function getCountAttr($value, $data) { $res = ExperienceTags::where(['experience_id' => $data['id'], 'uid' => UID])->count(); return $res; } }