ServiceController.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. namespace App\Admin\Controllers;
  3. use App\Models\Config;
  4. use Dcat\Admin\Form;
  5. use Dcat\Admin\Grid;
  6. use Dcat\Admin\Show;
  7. use Dcat\Admin\Http\Controllers\AdminController;
  8. class ServiceController extends AdminController
  9. {
  10. /**
  11. * Make a grid builder.
  12. *
  13. * @return Grid
  14. */
  15. protected function grid()
  16. {
  17. return Grid::make(new Config(), function (Grid $grid) {
  18. $grid->model()->whereIn('id', [7, 8, 9]);
  19. $grid->column('id')->sortable();
  20. $grid->column('desc', '标题');
  21. $grid->column('value', '值')->display(function ($item) {
  22. // 在这里通过 $this 获取当前行的数据
  23. $id = $this->id;
  24. // 根据条件判断是否显示值列
  25. if (9 == $id) {
  26. return "<a target='_blank' href='https://zhengda.oss-cn-chengdu.aliyuncs.com/" . $this->value . "'>查看二维码</a>";
  27. }
  28. return $item;
  29. });
  30. $grid->column('created_at');
  31. $grid->column('updated_at')->sortable();
  32. $grid->disableDeleteButton();
  33. $grid->disableCreateButton();
  34. $grid->disableViewButton();
  35. });
  36. }
  37. /**
  38. * Make a show builder.
  39. *
  40. * @return Show
  41. */
  42. protected function detail($id)
  43. {
  44. return Show::make($id, new Config(), function (Show $show) {
  45. $show->field('id');
  46. $show->field('key');
  47. $show->field('value');
  48. $show->field('desc');
  49. $show->field('created_at');
  50. $show->field('updated_at');
  51. });
  52. }
  53. /**
  54. * Make a form builder.
  55. *
  56. * @return Form
  57. */
  58. protected function form()
  59. {
  60. return Form::make(new Config(), function (Form $form) {
  61. $form->display('id');
  62. if (9 == $form->model()->id) {
  63. $form->image('value', '二维码')->disk('oss')->autoUpload()->saving(function ($res) {
  64. return $res;
  65. })->required();
  66. } else {
  67. $form->text('value', '值')->required();
  68. }
  69. $form->display('desc', '标题');
  70. $form->disableViewButton();
  71. $form->disableDeleteButton();
  72. });
  73. }
  74. }