column('sort'); $grid->column('name'); $grid->column('ratio')->display(function ($value) { return $value . '%'; }); $grid->column('growth_value'); $grid->model()->orderBy('sort', 'asc'); /** 操作 **/ //新增 if (Admin::user()->can('dcat.admin.agent.create')) { $grid->disableCreateButton(false); $grid->enableDialogCreate(); } //修改 $grid->showQuickEditButton(Admin::user()->can('dcat.admin.agent.edit')); //删除以及自定义操作 $grid->actions(function (Grid\Displayers\Actions $actions) { $actions->disableDelete(Admin::user()->cannot('dcat.admin.agent.destroy')); }); }); } /** * Make a show builder. * * @param mixed $id * * @return Show */ protected function detail($id) { return Show::make($id, new Agent(), function (Show $show) { $show->field('id'); $show->field('name'); $show->field('sort'); $show->filed('slug'); $show->column('ratio')->as(function ($value) { return $value . '%'; }); $show->field('growth_value'); $show->field('created_at'); $show->field('updated_at'); }); } /** * Make a form builder. * * @return Form */ protected function form() { return Form::make(new Agent(), function (Form $form) { $form->display('id'); $form->number('sort')->min(1)->required()->help('不可重复, 1级为最高')->rules(function (Form $form) { $rule = Rule::unique('agents', 'sort'); if ($id = $form->model()->id) { $rule->ignore($id); } return $rule; }); $form->text('name')->required(); $form->radio('slug')->options(Agent::$typeMap)->default(Agent::TYPE_FAVOITE); $form->number('ratio')->min(0)->max(100)->help('例如: 60%, 填写 60 即可'); $form->number('growth_value')->min(0)->default(0)->help('升级到此等级所需的成长值'); }); } public function destroy($id) { $vip = Agent::findOrFail($id); if ($vip->hasUser()) { throw new BizException(__('vip.options.deny_message')); } return parent::destroy($id); } }