ServiceController.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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) use ($grid) {
  22. // 在这里通过 $this 获取当前行的数据
  23. $id = $this->id;
  24. // 根据条件判断是否显示值列
  25. if ($id == 9) {
  26. return "<a target='_blank' href='https://zhengda.oss-cn-chengdu.aliyuncs.com/".$this->value."'>查看二维码</a>";
  27. } else {
  28. return $item;
  29. }
  30. });
  31. $grid->column('created_at');
  32. $grid->column('updated_at')->sortable();
  33. $grid->disableDeleteButton();
  34. $grid->disableCreateButton();
  35. $grid->disableViewButton();
  36. });
  37. }
  38. /**
  39. * Make a show builder.
  40. *
  41. * @param mixed $id
  42. *
  43. * @return Show
  44. */
  45. protected function detail($id)
  46. {
  47. return Show::make($id, new Config(), function (Show $show) {
  48. $show->field('id');
  49. $show->field('key');
  50. $show->field('value');
  51. $show->field('desc');
  52. $show->field('created_at');
  53. $show->field('updated_at');
  54. });
  55. }
  56. /**
  57. * Make a form builder.
  58. *
  59. * @return Form
  60. */
  61. protected function form()
  62. {
  63. return Form::make(new Config(), function (Form $form) {
  64. $form->display('id');
  65. if ($form->model()->id == 9){
  66. $form->image('value','二维码')->disk('oss')->autoUpload()->saving(function ($res) {
  67. return $res;
  68. })->required();
  69. }else{
  70. $form->text('value','值')->required();
  71. }
  72. $form->display('desc','标题');
  73. $form->disableViewButton();
  74. $form->disableDeleteButton();
  75. });
  76. }
  77. }