| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- <?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 PostModel extends BaseModel
- {
- // 设置数据表
- protected $table = 'posts';
- protected $appends = ['time_text'];
- public function getTimeTextAttribute()
- {
- return $this->create_time? datetime($this->create_time) : '';
- }
- public function getCoverAttribute($value)
- {
- return $value? get_image_url($value) : '';
- }
- public function setCoverAttribute($value)
- {
- return $value? get_image_path($value) : '';
- }
- public function getTagsAttribute($value)
- {
- $tags = $value? explode(',',$value) : [];
- return array_filter($tags);
- }
- public function getAlbumsAttribute($value)
- {
- return $value? json_decode($value,true) : [];
- }
- public function setAlbumsAttribute($value)
- {
- return $value? json_encode($value,256) : [];
- }
- public function setVideosAttribute($value)
- {
- return $value? json_encode($value,256) : [];
- }
- public function getVideosAttribute($value)
- {
- return $value? json_decode($value,true) : [];
- }
- /**
- * 发布用户
- * @return \Illuminate\Database\Eloquent\Relations\HasOne
- */
- public function user()
- {
- return $this->hasOne(MemberModel::class, 'id', 'user_id')
- ->select(['id','openid', 'mobile', 'nickname','balance', 'realname', 'status']);
- }
- /**
- * 评论记录
- * @return \Illuminate\Database\Eloquent\Relations\hasMany
- */
- public function records()
- {
- return $this->hasMany(PostRecordModel::class, 'source_id', 'id')
- ->where(['type'=>1,'status'=>1,'mark'=>1]);
- }
- /**
- * 点赞记录
- * @return \Illuminate\Database\Eloquent\Relations\hasMany
- */
- public function likes()
- {
- return $this->hasMany(PostRecordModel::class, 'source_id', 'id')
- ->where(['type'=>2,'status'=>1,'mark'=>1]);
- }
- /**
- * 是否点赞
- * @return \Illuminate\Database\Eloquent\Relations\hasMany
- */
- public function isLike()
- {
- return $this->hasOne(PostRecordModel::class, 'source_id', 'id')
- ->where(['type'=>2,'status'=>1,'mark'=>1]);
- }
- }
|