BaseVideoController.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <?php
  2. namespace App\Admin\Controllers;
  3. use App\Admin\Repositories\BaseProductCategory;
  4. use App\Admin\Repositories\BaseVideo;
  5. use App\Admin\Repositories\BaseVideoCategory;
  6. use Dcat\Admin\Form;
  7. use Dcat\Admin\Grid;
  8. use Dcat\Admin\Show;
  9. use Dcat\Admin\Http\Controllers\AdminController;
  10. use Dcat\Admin\Layout\Content;
  11. class BaseVideoController extends AdminController
  12. {
  13. /**
  14. * page index
  15. */
  16. public function index(Content $content)
  17. {
  18. return $content
  19. ->header('Video Management')
  20. ->description('all')
  21. ->breadcrumb(['text'=>'Video Management','url'=>''])
  22. ->body($this->grid());
  23. }
  24. /**
  25. * Make a grid builder.
  26. *
  27. * @return Grid
  28. */
  29. protected function grid()
  30. {
  31. return Grid::make(BaseVideo::with(['baseVideoCategory']), function (Grid $grid) {
  32. $grid->column('id')->sortable();
  33. $grid->column('title');
  34. $grid->column('base_video_category.name','Category Name');
  35. $grid->column('order')->orderable();
  36. $grid->column('is_pinned')->switch();
  37. $grid->column('enabled')->switch();
  38. $grid->column('created_at');
  39. $grid->column('updated_at')->sortable();
  40. // 筛选
  41. $grid->filter(function (Grid\Filter $filter) {
  42. $filter->equal('sku');
  43. $filter->like('title');
  44. $filter->equal('category_id','Category')->select(BaseVideoCategory::selectOptions());
  45. $filter->equal('enabled', 'enabled')->select([
  46. 1 => 'Yes',
  47. 0 => 'No',
  48. ]);
  49. });
  50. //排序
  51. $grid->model()->orderBy("is_pinned",'desc')->orderBy("order",'desc');
  52. //按钮
  53. });
  54. }
  55. /**
  56. * Make a show builder.
  57. *
  58. * @param mixed $id
  59. *
  60. * @return Show
  61. */
  62. protected function detail($id)
  63. {
  64. return Show::make($id, BaseVideo::with(['baseVideoCategory']), function (Show $show) {
  65. $show->field('id');
  66. $show->field('title');
  67. $show->field('base_video_category.name','Category Name');
  68. $show->html(function () {
  69. $content = $this->video_url;
  70. return view('admin::show.field', [
  71. 'wrapped'=>true,
  72. 'escape'=>false,
  73. 'width'=>['label' => '2','field'=>'8'],
  74. 'label'=>'Video Url',
  75. 'content'=>$content
  76. ]);
  77. });
  78. $show->field('video_url','Video player')->as(function ($value) {
  79. $html = '
  80. <iframe width="560" height="315" src="'.$value.'"
  81. title="YouTube video player"
  82. frameborder="0"
  83. allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
  84. allowfullscreen>
  85. </iframe>';
  86. return $html;
  87. })->unescape();
  88. $show->field('remark')->unescape();
  89. $show->field('enabled')->using([
  90. '0' => 'No', // 显示的状态名称
  91. '1' => 'Yes',
  92. ]);
  93. $show->field('created_at');
  94. $show->field('updated_at');
  95. });
  96. }
  97. /**
  98. * Make a form builder.
  99. *
  100. * @return Form
  101. */
  102. protected function form()
  103. {
  104. return Form::make(new BaseVideo(), function (Form $form) {
  105. $form->display('id');
  106. $form->text('title')->required();
  107. $form->select('category_id', 'Category Name')
  108. ->options(BaseVideoCategory::selectOptions())
  109. ->required();
  110. $form->url("video_url")->required();
  111. $form->editor('remark');
  112. $form->switch('is_pinned')->default(0);
  113. $form->switch('enabled')->default(1);
  114. });
  115. }
  116. }