column('id')->sortable(); $grid->column('name')->tree(); $grid->column('icon')->image(50, 50); $grid->column('is_show') ->if(function () { return Admin::user()->can('dcat.admin.product_categories.edit'); }) ->then(function (Column $column) { $column->switch(); }) ->else(function (Column $column) { $column->bool(); }); $grid->column('is_recommend') ->if(function () { return Admin::user()->can('dcat.admin.product_categories.edit'); }) ->then(function (Column $column) { $column->switch(); }) ->else(function (Column $column) { $column->bool(); }); $grid->column('sort'); $grid->column('created_at')->sortable(); //排序 $grid->model()->orderBy('created_at', 'desc'); /** 操作 **/ //新增 if (Admin::user()->can('dcat.admin.product_categories.create')) { $grid->disableCreateButton(false); $grid->enableDialogCreate(); } //修改 $grid->showQuickEditButton(Admin::user()->can('dcat.admin.product_categories.edit')); //删除以及自定义操作 $grid->actions(function (Grid\Displayers\Actions $actions) { $actions->disableDelete(Admin::user()->cannot('dcat.admin.product_categories.destroy')); }); /** 查询 **/ $grid->filter(function (Grid\Filter $filter) { $filter->panel(); $filter->equal('name')->width(3); }); }); } /** * Make a show builder. * * @param mixed $id * * @return Show */ protected function detail($id) { return Show::make($id, new ProductCategory(), function (Show $show) { $show->field('id'); $show->field('name'); $show->field('icon'); $show->field('is_show'); $show->field('sort'); $show->field('parent_id'); $show->field('created_at'); $show->field('updated_at'); }); } /** * Make a form builder. * * @return Form */ protected function form() { return Form::make(new ProductCategory(), function (Form $form) { $form->display('id'); $form->select('parent_id')->options(ProductCategoryModel::selectOptions()); $form->text('name')->required(); $form->image('icon') ->move('product/'.Carbon::now()->toDateString()) ->saveFullUrl() ->removable(false) ->autoUpload(); $form->switch('is_show'); $form->switch('is_recommend'); $form->number('sort')->default(0); $form->display('created_at'); $form->display('updated_at'); }); } }