1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- <?php
- namespace App\Admin\Controllers;
- use App\Models\Config;
- use Dcat\Admin\Form;
- use Dcat\Admin\Grid;
- use Dcat\Admin\Show;
- use Dcat\Admin\Http\Controllers\AdminController;
- class OtherController extends AdminController
- {
- /**
- * Make a grid builder.
- *
- * @return Grid
- */
- protected function grid()
- {
- return Grid::make(new Config(), function (Grid $grid) {
- $grid->model()->whereIn('id', [5, 6, 11, 25]);
- $grid->column('id')->sortable();
- $grid->column('desc', '标题');
- $grid->column('value', '值')->display(function ($item) {
- // 在这里通过 $this 获取当前行的数据
- $id = $this->id;
- // 根据条件判断是否显示值列
- if (12 == $id) {
- return $item . '%';
- }
- return $item;
- });
- $grid->column('created_at');
- $grid->column('updated_at')->sortable();
- $grid->disableDeleteButton();
- $grid->disableCreateButton();
- $grid->disableViewButton();
- });
- }
- /**
- * Make a show builder.
- *
- * @return Show
- */
- protected function detail($id)
- {
- return Show::make($id, new Config(), function (Show $show) {
- $show->field('id');
- $show->field('key');
- $show->field('value');
- $show->field('desc');
- $show->field('created_at');
- $show->field('updated_at');
- });
- }
- /**
- * Make a form builder.
- *
- * @return Form
- */
- protected function form()
- {
- return Form::make(new Config(), function (Form $form) {
- $form->display('id');
- if (11 == $form->model()->id) {
- $form->textarea('value', '值')->required();
- } elseif (12 == $form->model()->id) {
- $form->number('value', '值')->required();
- } else {
- $form->text('value', '值')->required();
- }
- $form->display('desc', '标题');
- $form->disableViewButton();
- $form->disableDeleteButton();
- });
- }
- }
|