fastadmin 关联预载入限制关联表的字段的显示:$v->hidden(['roominfo'=>['builtup_area','carpet_area', 'addons']]);

public function index()
    {
        //设置过滤方法
        $this->request->filter(['strip_tags', 'trim']);
        if ($this->request->isAjax()) {
            //如果发送的来源是Selectpage,则转发到Selectpage
            if ($this->request->request('keyField')) {
                return $this->selectpage();
            }
            list($where, $sort, $order, $offset, $limit) = $this->buildparams();
 
            $list = $this->model
                ->with(['roominfo'])
                ->where($where)
                ->order($sort, $order)
                ->paginate($limit);
 
            foreach ($list as $k=>$v) {
                //$v->avatar = $v->avatar ? cdnurl($v->avatar, true) : letter_avatar($v->nickname);
                $v->hidden(['roominfo'=>['builtup_area','carpet_area', 'addons']]);
                //$row->visible(['builtup_area','carpet_area','deposit']);
            }
 
            $result = array("total" => $list->total(), "rows" => $list->items());
 
            return json($result);
        }
        return $this->view->fetch();
    }

 

posted @ 2023-10-09 09:14  blog_zss小帅-博客猿  阅读(80)  评论(0编辑  收藏  举报