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; } }