鍍金池/ 問答/PHP/ TP5 field() 方法 字段不顯示

TP5 field() 方法 字段不顯示

TP5 模型用field() 方法查詢 有一個(gè)字段不顯示

商品表 模型

/**
     * 定義商品和商品評(píng)論表之間得關(guān)系
     *
     * @return \think\model\relation\HasMany
     */
    public function goodsComment() {
        return $this->hasMany('MallComment', 'goods_id', 'id')->field('user_id,comment,comment_type,create_time');
    }

控制器使用

        $goodsInfo = Goods::goodsInfo($data['goods_id']);
        $goodsInfo->goodsComment()->order('create_time desc')->limit(0, 1)->select();

返回結(jié)果

   "goodsComment": [
            {
                "user_id": 33,
                "comment": "你好",
                "comment_type": 2,
                "user": {
                    "nickname": "XX",
                    "photo": "9f1cd8fd29d4b17ccd93b333ff558118.png"
                }
            },
            {
                "user_id": 33,
                "comment": "哈哈",
                "comment_type": 1,
                "user": {
                    "nickname": "XX",
                    "photo": "9f1cd8fd29d4b17ccd93b333ff558118.png"
                }
            }
        ]

返回結(jié)果中并沒有create_time字段 并且 limit 和 order方法都失效了 數(shù)據(jù)庫里是存在值得

clipboard.png

請(qǐng)大神指教下

回答
編輯回答
溫衫

繼承父模型隱藏create_time

2018年3月16日 12:22