| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- <?php
- // +----------------------------------------------------------------------
- // | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
- // +----------------------------------------------------------------------
- // | 版权所有 2017~2021 LARAVEL研发中心
- // +----------------------------------------------------------------------
- // | 官方网站: http://www.laravel.cn
- // +----------------------------------------------------------------------
- // | Author: laravel开发员 <laravel.qq.com>
- // +----------------------------------------------------------------------
- namespace App\Models;
- /**
- * 笔记动态/点赞或评论记录-模型
- * @author laravel开发员
- * @since 2020/11/11
- * @package App\Models
- */
- class PostRecordModel extends BaseModel
- {
- // 设置数据表
- protected $table = 'posts_records';
- protected $appends = ['time_text'];
- public function getAlbumsAttribute($value)
- {
- return $value? get_images_preview($value,'url',2) : [];
- }
- public function getTimeTextAttribute()
- {
- return $this->create_time? dateFormat($this->create_time,'Y-m-d') : '';
- }
- /**
- * 发布用户
- * @return \Illuminate\Database\Eloquent\Relations\HasOne
- */
- public function user()
- {
- return $this->hasOne(MemberModel::class, 'id', 'user_id')
- ->select(['id','openid', 'mobile', 'nickname','avatar','balance', 'realname', 'status']);
- }
- /**
- * 回复用户
- * @return \Illuminate\Database\Eloquent\Relations\HasOne
- */
- public function replyUser()
- {
- return $this->hasOne(MemberModel::class, 'id', 'reply_uid')
- ->select(['id','openid', 'mobile', 'nickname','avatar','balance', 'realname', 'status']);
- }
- /**
- * 笔记
- * @return \Illuminate\Database\Eloquent\Relations\HasOne
- */
- public function posts()
- {
- return $this->hasOne(PostModel::class, 'id', 'source_id')
- ->select(['id','title', 'thumb', 'type','user_id', 'tags','status']);
- }
- /**
- * 回复
- * @return \Illuminate\Database\Eloquent\Relations\HasOne
- */
- public function reply()
- {
- return $this->hasOne(PostRecordModel::class, 'id','reply_id');
- }
- /**
- * 回复
- * @return \Illuminate\Database\Eloquent\Relations\hasMany
- */
- public function replys()
- {
- return $this->hasMany(PostRecordModel::class, 'reply_id', 'id')->with(['user','replyUser']);
- }
- }
|