123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- <?php
- namespace App\Admin\Controllers;
- use App\Models\MentalityDrillCategory;
- use App\Models\MentalityDrillExtend;
- use Encore\Admin\Controllers\AdminController;
- use Encore\Admin\Form;
- use Encore\Admin\Grid;
- use Encore\Admin\Show;
- use App\Models\MentalityDrill;
- class MentalityDrillExtendController extends AdminController
- {
- /**
- * Title for current resource.
- *
- * @var string
- */
- protected $title = '音视频';
- /**
- * Make a grid builder.
- *
- * @return Grid
- */
- protected function grid()
- {
- $grid = new Grid(new MentalityDrillExtend());
- $grid->filter(function(\Encore\Admin\Grid\Filter $filter){
- // 在这里添加字段过滤器
- $filter->like('name', '名称');
- $filter->expand();
- });
- $grid->column('id', __('Id'));
- $grid->column('drill_id', __('训练'))->display(function ($id) {
- if ($id > 0){
- $mentalityDrillData = MentalityDrill::find($id);
- if ($mentalityDrillData){
- return $mentalityDrillData->title;
- }
- }
- return '';
- });
- $grid->column('name', __('名称'));
- $grid->column('time', __('时长'));
- $grid->column('type', __('类别'))->display(function ($type) {
- return MentalityDrillExtend::$typeMap[$type];
- });
- $grid->column('created_at', __('创建时间'));
- $grid->column('updated_at', __('更新时间'));
- return $grid;
- }
- /**
- * Make a show builder.
- *
- * @param mixed $id
- * @return Show
- */
- protected function detail($id)
- {
- $show = new Show(MentalityDrillExtend::findOrFail($id));
- $show->field('id', __('Id'));
- $show->field('drill_id', __('Drill id'));
- $show->field('name', __('Name'));
- $show->field('time', __('Time'));
- $show->field('src', __('Src'));
- $show->field('created_at', __('Created at'));
- $show->field('updated_at', __('Updated at'));
- $show->field('deleted_at', __('Deleted at'));
- return $show;
- }
- /**
- * Make a form builder.
- *
- * @return Form
- */
- protected function form()
- {
- $form = new Form(new MentalityDrillExtend());
- $select = MentalityDrill::get(['id','title as name'])->pluck('name','id');
- $form->select('drill_id', __('训练'))->options($select)->required();
- $form->select('type', __('类别'))->options(MentalityDrillExtend::$typeMap)->required();
- $form->text('name', __('名称'))->required();
- $form->text('time', __('时长'))->required();
- $form->file('src', __('音视频'))->removable()->uniqueName()->move('videos/'.date('Y').'/'.date('m'));
- $form->image('pic', __('背景图片'));
- return $form;
- }
- }
|