FastAdmin给快速搜索增加搜索字段的方法

如何给FastAdmin给快速搜索增加搜索字段?从基类文件Backend.php复制如下的代码到控制器.php,然后增加字段名即可.

    /**
     * 快速搜索时执行查找的字段
     */
    protected $searchFields = 'id,name';

上面是快速搜索字段的使用,那么关联搜索呢?那就是在具体方法中设置即可,比如index,如果是一键curd的时候选择了关联模型那么自动会有.

    /**
     * 查看
     */
    public function index()
    {
        //当前是否为关联查询
        $this->relationSearch = true;
        //设置过滤方法
        $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(['admin'])
                    ->where($where)
                    ->order($sort, $order)
                    ->paginate($limit);

            foreach ($list as $row) {
                $row->getRelation('admin')->visible(['nickname','id']);
            }

            $result = array("total" => $list->total(), "rows" => $list->items());

            return json($result);
        }
        return $this->view->fetch();
    }


微信扫描下方的二维码阅读本文

没有账号? 忘记密码?

社交账号快速登录