123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- <?php
- namespace App\Admin\Controllers\Episode;
- use App\Models\Episode;
- use App\Models\EpisodesList;
- use Dcat\Admin\Form;
- use Dcat\Admin\Grid;
- use Dcat\Admin\Layout\Content;
- use Dcat\Admin\Show;
- use Dcat\Admin\Http\Controllers\AdminController;
- class EpisodesListController extends AdminController
- {
- /* @var Episode $episode*/
- private $episode;
- protected function title()
- {
- return $this->episode->name;
- }
- protected function content(Content $content, $episodeId = 1)
- {
- $this->episode = Episode::find($episodeId);
- return $content
- ->translation($this->translation())
- ->breadcrumb(
- ['text' => $this->episode->name],
- ['text' => '剧集上传'],
- )
- ->title($this->title())
- ->description('剧集上传');
- }
- public function index(Content $content,$episodeId = 0)
- {
- return $this->content($content,$episodeId)
- ->body($this->grid());
- }
- public function create(Content $content,$episodeId = 0)
- {
- return $this->content($content,$episodeId)
- ->body($this->form());
- }
- public function store($episodeId = 0)
- {
- $this->episode = Episode::find($episodeId);
- return $this->form()->store();
- }
- public function edit($id, Content $content, $episodeId = 0)
- {
- return $this->content($content,$episodeId)
- ->body($this->form()->edit($id));
- }
- /**
- * Make a grid builder.
- *
- * @return Grid
- */
- protected function grid()
- {
- return Grid::make(EpisodesList::with(['episode'])->where('episodes_id', $this->episode->id), function (Grid $grid) {
- $grid->column('id')->sortable();
- $grid->column('episode.name','剧集名称');
- $grid->column('sort')->display(function (){
- return '第'.$this->sort.'集';
- })->editable();
- $grid->column('is_free')
- ->using(config('global.episode_free'))
- ->label(['success', 'primary'])->sortable();
- $grid->column('sale_price')->editable();
- $grid->column('url')->display(function (){
- return '<video src="'.$this->url.'" width="200" controls></vedio>';
- });
- $grid->disableViewButton();
- });
- }
- /**
- * Make a show builder.
- *
- * @param mixed $id
- *
- * @return Show
- */
- protected function detail($id)
- {
- return Show::make($id, new EpisodesList(), function (Show $show) {
- $show->field('id');
- $show->field('episodes_id');
- $show->field('sort');
- $show->field('url');
- $show->field('created_at');
- $show->field('updated_at');
- });
- }
- /**
- * Make a form builder.
- *
- * @return Form
- */
- protected function form()
- {
- return Form::make(new EpisodesList(), function (Form $form) {
- $form->display('id');
- $form->hidden('episodes_id')->value($this->episode->id);
- $form->number('sort')->min(1);
- $form->radio('is_free')
- ->options(config('global.episode_free'))
- ->when(1, function (Form $form) {
- $form->number('sale_price');
- })->default(1);
- $form->file('url')->chunkSize(1024)->maxSize(1024 * 1024)->saveFullUrl()
- ->uniqueName()->autoUpload()
- ->autoSave(false)
- ->removable(false)
- ->width(4)->required();;
- $form->display('created_at');
- $form->disableViewButton();
- $form->disableDeleteButton();
- $form->disableListButton();
- $form->disableEditingCheck();
- $form->disableViewCheck();
- $form->disableCreatingCheck();
- });
- }
- }
|