123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- <?php
- namespace App\Admin\Controllers;
- use App\Models\MentalityDrill;
- use App\Models\MentalityDrillCategory;
- use App\Models\MentalityDrillsSubject;
- use Encore\Admin\Controllers\AdminController;
- use Encore\Admin\Form;
- use Encore\Admin\Grid;
- use Encore\Admin\Show;
- use Illuminate\Support\Facades\DB;
- /**
- * 课程相关控制
- */
- class MentalityDrillsSubjectController extends AdminController
- {
- /**
- * Title for current resource.
- *
- * @var string
- */
- protected $title = '课程';
- /**
- * Make a grid builder.
- *
- * @return Grid
- */
- protected function grid()
- {
- $grid = new Grid(new MentalityDrillsSubject());
- $grid->filter(function($filter){
- $filter->disableIdFilter();
- // $filter->where(function($query){
- // $query->where('activity_range_id=' . $_GET['activity_range_id']);
- // },'hidden');
- // 在这里添加字段过滤器
- $filter->like('name', '课程名称');
- $tableName = MentalityDrillCategory::query()->getModel()->getTable();
- $isSubject = MentalityDrillCategory::isSubjectYes;
- $select = MentalityDrill::query()
- ->whereRaw(DB::raw("category_id in (select id from {$tableName} where is_subject = {$isSubject} and deleted_at is null)"))
- ->get(['id','title as name'])
- ->pluck('name','id');
- $filter->equal('mentality_drills_id', '训练')->select(
- $select
- );
- $filter->expand();
- });
- $grid->column('id', __('Id'));
- $grid->column('mentality_drills_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 MentalityDrillsSubject::$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(MentalityDrillsSubject::findOrFail($id));
- $show->field('id', __('Id'));
- $show->field('mentality_drills_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 MentalityDrillsSubject());
- $tableName = MentalityDrillCategory::query()->getModel()->getTable();
- $isSubject = MentalityDrillCategory::isSubjectYes;
- $select = MentalityDrill::query()
- ->whereRaw(DB::raw("category_id in (select id from {$tableName} where is_subject = {$isSubject} and deleted_at is null)"))
- ->get(['id','title as name'])
- ->pluck('name','id');
- $form->select('mentality_drills_id', __('训练'))->options($select)->required();
- // $form->select('type', __('类别'))->options(MentalityDrillsSubject::$typeMap)->required();
- $form->hidden("type","类别")->value(MentalityDrillsSubject::TYPE_2);
- $form->text('name', __('课程名称'))->required();
- $form->text('time', __('时长'))->required();
- $form->file('src', __('视频'))->removable()->uniqueName()->move('videos/'.date('Y').'/'.date('m'));
- $form->image('pic', __('背景图片'));
- return $form;
- }
- }
|