column('id', __('Id')); $grid->column('category_id', __('分类'))->display(function ($pid) { if ($pid>0){ $scaleCategoryData = ScaleCategory::find($pid); if ($scaleCategoryData){ return $scaleCategoryData->name; } } return ''; }); $grid->column('second_id', __('二级分类'))->display(function ($pid) { if ($pid>0){ $scaleCategoryData = ScaleCategory::find($pid); if ($scaleCategoryData){ return $scaleCategoryData->name; } } return ''; }); $grid->column('title', __('标题')); $grid->column('time', __('测试时间')); $grid->column('suitable_for_the_crowd', __('适合人群')); $grid->column('number_of_questions', __('问题数')); $grid->column('number_of_replay', __('报告数')); $grid->column('number_of_test', __('测试次数')); $grid->column('rank', __('排序 越大越前')); $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(Scale::findOrFail($id)); $show->field('id', __('Id')); $show->field('category_id', __('Category id')); $show->field('third_id', __('Third id')); $show->field('title', __('Title')); $show->field('subtitle', __('Subtitle')); $show->field('pic', __('Pic')); $show->field('content', __('Content')); $show->field('time', __('Time')); $show->field('suitable_for_the_crowd', __('Suitable for the crowd')); $show->field('number_of_questions', __('Number of questions')); $show->field('number_of_replay', __('Number of replay')); $show->field('number_of_test', __('Number of test')); $show->field('notice', __('Notice')); $show->field('rank', __('Rank')); $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 Scale()); $thirdScale = ThirdScale::get(['id', 'title as name'])->pluck('name','id'); $form->select('third_id', __('远程量表'))->options($thirdScale)->required(); $cloumns = ScaleCategory::where('pid', 0)->where('deleted_at',null)->get(['id','name'])->pluck('name','id'); $form->select('category_id', __('分类'))->options($cloumns)->rules("required")->load('second_id', '/admin/scale_second_category'); $second = []; if($form->isEditing()){ $model = Scale::find(request()->route()->parameters()['scale']); if($model) { $second = ScaleCategory::where('pid','=',$model->category_id)->where('deleted_at',null)->get(['id','name'])->pluck('name','id'); } } $form->select('second_id', __('二级分类'))->options($second);; $form->text('title', __('标题'))->required(); $form->text('subtitle', __('副标题'))->required(); $form->image('pic', __('图片'))->required(); $form->editor('content', __('内容'))->required(); $form->number('time', __('测试时间(分钟)'))->required(); $form->text('suitable_for_the_crowd', __('适合人群'))->required(); $form->number('number_of_questions', __('问题数'))->default(0); $form->number('number_of_replay', __('报告数'))->default(0); $form->number('number_of_test', __('测试次数'))->default(0); $form->textarea('notice', __('测试须知'))->required(); $form->number('rank', __('排序 越大越前'))->default(0); $form->list('comment_tag', __('推荐标签')); return $form; } public function getSecondCategory(Request $request ) { $pid = $request->input('q'); return ScaleCategory::where('pid', $pid)->select('name as text','id')->get()->toArray(); } }