ShowroomCaseController.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php
  2. namespace App\Admin\Controllers;
  3. use App\Models\Showroom;
  4. use App\Models\ShowroomCase;
  5. use Dcat\Admin\Form;
  6. use Dcat\Admin\Grid;
  7. use Dcat\Admin\Show;
  8. use Dcat\Admin\Http\Controllers\AdminController;
  9. class ShowroomCaseController extends AdminController
  10. {
  11. /**
  12. * Make a grid builder.
  13. *
  14. * @return Grid
  15. */
  16. protected function grid()
  17. {
  18. return Grid::make(ShowroomCase::with('showroom'), function (Grid $grid) {
  19. $grid->column('id')->sortable();
  20. $grid->column('showroom_id','展厅名称')->display(function (){
  21. return $this->showroom->name;
  22. });
  23. $grid->column('name');
  24. $grid->column('videos')->display(function (){
  25. $html = '';
  26. foreach ($this->videos as $key => $video){
  27. $html .= "<video src='{$video}' width='200' controls>";
  28. }
  29. return $html;
  30. });
  31. $grid->column('images')->display(function (){
  32. $html = '';
  33. foreach ($this->images as $image){
  34. $html .= '<img data-action="preview-img" src="'.$image.'"
  35. style="max-width:80px;max-height:80px;cursor:pointer"
  36. class="img img-thumbnail">';
  37. }
  38. return $html;
  39. });
  40. $grid->column('sort')->editable();
  41. $grid->column('is_opened')->switch();
  42. $grid->column('created_at');
  43. $grid->filter(function (Grid\Filter $filter) {
  44. $filter->panel();
  45. $filter->like('name')->width(2);
  46. $filter->equal('showroom_id','展厅')->select(function (){
  47. return Showroom::select(['id','name'])->get()->pluck('name','id')->toArray();
  48. })->width(2);
  49. });
  50. $grid->disableViewButton();
  51. });
  52. }
  53. /**
  54. * Make a show builder.
  55. *
  56. * @param mixed $id
  57. *
  58. * @return Show
  59. */
  60. protected function detail($id)
  61. {
  62. return Show::make($id, new ShowroomCase(), function (Show $show) {
  63. $show->field('id');
  64. $show->field('showroom_id');
  65. $show->field('name');
  66. $show->field('videos');
  67. $show->field('images');
  68. $show->field('sort');
  69. $show->field('is_opened');
  70. $show->field('created_at');
  71. $show->field('updated_at');
  72. });
  73. }
  74. /**
  75. * Make a form builder.
  76. *
  77. * @return Form
  78. */
  79. protected function form()
  80. {
  81. return Form::make(new ShowroomCase(), function (Form $form) {
  82. $form->display('id');
  83. $cates = Showroom::select(['id','name'])
  84. ->where('is_opened',1)->get()->toArray();
  85. $form->select('showroom_id')
  86. ->options(array_column($cates,'name','id'))
  87. ->required();;
  88. $form->text('name')->required();
  89. $form->multipleFile('videos')->saveFullUrl()
  90. ->mimeTypes('video/*')
  91. ->chunkSize(4096)
  92. ->maxSize(1024 * 1024)
  93. ->uniqueName()
  94. ->autoUpload()
  95. ->autoSave(false)
  96. ->removable(false)
  97. ->width(4);
  98. $form->multipleImage('images')->saveFullUrl()
  99. ->uniqueName()->autoUpload()
  100. ->autoSave(false)
  101. ->removable(false)
  102. ->width(4);
  103. $form->number('sort');
  104. $form->radio('is_opened')
  105. ->options(config('global.bool_status'))
  106. ->default(1);
  107. $form->disableViewButton();
  108. $form->disableDeleteButton();
  109. $form->disableListButton();
  110. $form->disableEditingCheck();
  111. $form->disableViewCheck();
  112. $form->disableCreatingCheck();
  113. });
  114. }
  115. }