文章表用with关联评论表,如何控制显示部分文章表字段?
已知文章表字段为
id content time
评论表字段为
id article_id content time
我想查询出文章内容和关联的评论内容,但是不想显示文章的创建时间,请问怎么解决呢?
目前想用
$detail = Article::select(['content'])->with(['comment'])->where('id',49)->first();
return response()->json($detail);
但是结果为comment下面是空的,当我用
$detail = Article::select(['content','comment.*'])->with(['comment'])->where('id',49)->first();
return response()->json($detail);
又提示comment字段不存在(肯定是不存在的),那么怎么解决这个问题呢?
$detail = Article::select(['content','id'])->with(['comment'])->where('id',49)->first(); with关联的时候id要查的