column('id')->sortable(); $grid->column('user_name'); $grid->column('type') ->using(config('global.user_type')) ->label(['info','primary','success']);; $grid->column('account'); $grid->column('status') ->using(config('global.user_status')) ->label(['danger','success'])->switch(); $grid->column('remark')->editable(); $grid->column('created_at'); $grid->actions(function (Grid\Displayers\Actions $actions) { $actions->append(new ResetPassword(Account::class, $actions->row->id)); }); $grid->disableViewButton(); $grid->export() ->titles([ 'user_name' => '用户名', 'type_text' => '用户类型', 'account' => '账号', 'status_text' => '状态', 'remark' => '备注', 'created_at' => '添加时间', ])->rows(function ($rows){ foreach ($rows as &$row) { $row['type_text']= config('global.user_type')[$row['type']]; $row['status_text'] = config('global.user_status')[$row['status']]; } return $rows; }) ->xlsx() ->disableExportSelectedRow(); }); } /** * Make a show builder. * * @param mixed $id * * @return Show */ protected function detail($id) { return Show::make($id, new Account(), function (Show $show) { $show->field('id'); $show->field('user_name'); $show->field('account'); $show->field('password'); $show->field('type'); $show->field('remark'); $show->field('status'); $show->field('created_at'); $show->field('updated_at'); }); } /** * Make a form builder. * * @return Form */ protected function form() { return Form::make(new Account(), function (Form $form) { $form->display('id'); $form->text('user_name')->required(); $form->mobile('account') ->placeholder('手机号') ->required() ->rules(function ($form) { // 如果不是编辑状态,则添加字段唯一验证 if (!$form->model()->id) { return 'unique:accounts'; } }); $form->password('password') ->placeholder('默认123456'); $form->radio('type') ->options(config('global.user_type')) ->default(1); $form->radio('status') ->options(config('global.user_status')) ->default(1); $form->textarea('remark'); // $form->display('created_at'); //$form->display('updated_at'); $form->saving(function (Form $form) { // 如果不是编辑状态 不填写密码默认123456 if (!$form->model()->id) { if(!$form->password){ $form->password = \Hash::make(123456); }else{ $form->password = \Hash::make($form->password); } }else{ if ($form->password && $form->model()->password != $form->password) { $form->password = \Hash::make($form->password); } if (! $form->password) { $form->deleteInput('password'); } } }); $form->disableViewButton(); $form->disableDeleteButton(); $form->disableListButton(); $form->disableEditingCheck(); $form->disableViewCheck(); $form->disableCreatingCheck(); }); } }