$goods_lists = $this->model
->with([
"info" => function ($query) {
$query->where(['is_del' => 0]);
}
])
->where($this->model->getCategoryIdsWhere())
->where($where_goods_ids)
->whereOr($where_filter_ids)
->limit(20)
->select(); // 分页
foreach ($goods_lists as $row){
$row->visible(['id','product_code','product_name','icon_images_formal',]); // 显示字段
$row->hidden(['password']); // 隐藏字段
$row->getRelation('info')->visible(['image_formal','description',]); // info关联处理
}
- visible 需要显示的是什么字段
- hidden 隐藏的什么字段
- getRelation 关联操作