BaseVideoController.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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(new BaseVideo(), 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->orderby->()->orderBy("order",'asc');
  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(['']), function (Show $show) {
  65. $show->field('id');
  66. $show->field('title');
  67. $show->field('base_video_category.name','Category Name');
  68. $show->field('remark');
  69. $show->field('enabled')->using([
  70. '0' => 'No', // 显示的状态名称
  71. '1' => 'Yes',
  72. ]);
  73. $show->field('created_at');
  74. $show->field('updated_at');
  75. });
  76. }
  77. /**
  78. * Make a form builder.
  79. *
  80. * @return Form
  81. */
  82. protected function form()
  83. {
  84. return Form::make(new BaseVideo(), function (Form $form) {
  85. $form->display('id');
  86. $form->text('title')->required();
  87. $form->select('category_id', 'Category Name')
  88. ->options(BaseVideoCategory::selectOptions())
  89. ->required();
  90. $form->url("video_url")->required();
  91. $form->editor('remark');
  92. $form->switch('is_pinned')->default(0);
  93. $form->switch('enabled')->default(1);
  94. });
  95. }
  96. }