EpisodesListController.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php
  2. namespace App\Admin\Controllers\Episode;
  3. use App\Models\Episode;
  4. use App\Models\EpisodesList;
  5. use Dcat\Admin\Form;
  6. use Dcat\Admin\Grid;
  7. use Dcat\Admin\Layout\Content;
  8. use Dcat\Admin\Show;
  9. use Dcat\Admin\Http\Controllers\AdminController;
  10. class EpisodesListController extends AdminController
  11. {
  12. /* @var Episode $episode*/
  13. private $episode;
  14. protected function title()
  15. {
  16. return $this->episode->name;
  17. }
  18. protected function content(Content $content, $episodeId = 1)
  19. {
  20. $this->episode = Episode::find($episodeId);
  21. return $content
  22. ->translation($this->translation())
  23. ->breadcrumb(
  24. ['text' => $this->episode->name],
  25. ['text' => '剧集上传'],
  26. )
  27. ->title($this->title())
  28. ->description('剧集上传');
  29. }
  30. public function index(Content $content,$episodeId = 0)
  31. {
  32. return $this->content($content,$episodeId)
  33. ->body($this->grid());
  34. }
  35. public function create(Content $content,$episodeId = 0)
  36. {
  37. return $this->content($content,$episodeId)
  38. ->body($this->form());
  39. }
  40. public function store($episodeId = 0)
  41. {
  42. $this->episode = Episode::find($episodeId);
  43. return $this->form()->store();
  44. }
  45. public function edit($id, Content $content, $episodeId = 0)
  46. {
  47. return $this->content($content,$episodeId)
  48. ->body($this->form()->edit($id));
  49. }
  50. /**
  51. * Make a grid builder.
  52. *
  53. * @return Grid
  54. */
  55. protected function grid()
  56. {
  57. return Grid::make(EpisodesList::with(['episode'])->where('episodes_id', $this->episode->id), function (Grid $grid) {
  58. $grid->column('id')->sortable();
  59. $grid->column('episode.name','剧集名称');
  60. $grid->column('sort')->display(function (){
  61. return '第'.$this->sort.'集';
  62. })->editable();
  63. $grid->column('url')->display(function (){
  64. return '<video src="'.$this->url.'" width="200" controls></vedio>';
  65. });
  66. $grid->disableViewButton();
  67. });
  68. }
  69. /**
  70. * Make a show builder.
  71. *
  72. * @param mixed $id
  73. *
  74. * @return Show
  75. */
  76. protected function detail($id)
  77. {
  78. return Show::make($id, new EpisodesList(), function (Show $show) {
  79. $show->field('id');
  80. $show->field('episodes_id');
  81. $show->field('sort');
  82. $show->field('url');
  83. $show->field('created_at');
  84. $show->field('updated_at');
  85. });
  86. }
  87. /**
  88. * Make a form builder.
  89. *
  90. * @return Form
  91. */
  92. protected function form()
  93. {
  94. return Form::make(new EpisodesList(), function (Form $form) {
  95. $form->display('id');
  96. $form->hidden('episodes_id')->value($this->episode->id);
  97. $form->number('sort')->min(1);
  98. $form->file('url')->chunkSize(1024)->maxSize(1024 * 1024)->saveFullUrl()
  99. ->uniqueName()->autoUpload()
  100. ->autoSave(false)
  101. ->removable(false)
  102. ->width(4)->required();;
  103. $form->display('created_at');
  104. $form->disableViewButton();
  105. $form->disableDeleteButton();
  106. $form->disableListButton();
  107. $form->disableEditingCheck();
  108. $form->disableViewCheck();
  109. $form->disableCreatingCheck();
  110. });
  111. }
  112. }