IdeaComment.php 1.1 KB
<?php


namespace app\api\model;


use think\Model;

class IdeaComment extends Model
{
    protected $append = [
//        'like_nicknames_text',
        'createtime_text',
        'images_text'
    ];

//    public function getLikeNicknamesTextAttr($value,$data)
//    {
//        $value = isset($data['like_nicknames']) ? explode(',',$data['like_nicknames']) : [];
//        return $value;
//    }

    public function getImagesTextAttr($value,$data)
    {
        $value = isset($data['images']) && !empty($data['images']) ? explode(',',$data['images']) : [];
        foreach ($value as $key => $val){
            $value[$key] = cdnurl($val,true);
        }
        return $value;
    }

    public function getCreatetimeTextAttr($value,$data)
    {
        $value = isset($data['createtime']) && $data['createtime'] > 1 ? date('Y-m-d',$data['createtime']) : '';
        return $value;
    }

    public function user()
    {
        return $this->belongsTo('User','user_id','id');
    }

    public function touser()
    {
        return $this->belongsTo('ToUser','touser_id','id');
    }
}