2.修改配置文件 Encore\Admin\Grid
添加一个方法
/** * Output as string. * * @return string */ public function __toString() { return $this->render(); } /** * Make a grid builder. * * @return Grid */ protected function grid() { $tab = new Tab(); //创建一个tab $content = \Admin::grid(new GoodsZp(), function (Grid $grid) { // $grid = new Grid(new GoodsZp()); 原始的注释掉 $grid->selector(function (Grid\Tools\Selector $selector) { $selector->select('id', '活动状态', [ '' => '所有活动', 1 => '未开始', 2 => '进行中', 3 => '已结束', 4 => '已失效', ], function ($query, $value) { // dd($value); $arr = $this->goods->getTimeStart($value[0]); //符合条件的数组id // dd($arr); if (count($arr) > 1) { $query->whereBetween('id', $arr); } else { $query->where('id', $arr[0]); } }); }); //回收站 $grid->filter(function ($filter) { // 范围过滤器,调用模型的`onlyTrashed`方法,查询出被软删除的数据。 $filter->scope('trashed', '回收站')->onlyTrashed(); }); //回收站恢复 $grid->actions(function ($actions) { if (\request('_scope_') == 'trashed') { $actions->add(new Restore()); } }); $grid->column('id', __('Id')); $grid->column('title', __('Title')); $grid->column('goods_no', __('Goods no')); $grid->column('created_at', __('Created at')); $grid->column('updated_at', __('Updated at')); $grid->column('deleted_at', __('Deleted at')); // return $grid; }); $tab->add('选项卡一', $content); $tab->add('选项卡二', $content); return $tab; }