在 with 查询中只查询个别字段

   $data = Answer::with(['questionInfo' => function ($query) {
            $query->select('id', 'title');
        }])->where("user_id",8)
            ->orderBy("created_at", 'desc')
            ->select(["id", "question_id", "content", "created_at"]);

width里面一定要加id

posted @ 2020-02-05 18:35  明明一颗大白菜  阅读(373)  评论(0编辑  收藏  举报
<-- -->