header('试题管理') ->description('列表') ->body($this->grid()); } /** * Show interface. * * @param mixed $id * @param Content $content * @return Content */ public function show($id, Content $content) { return $content ->header('试题管理') ->description('详情') ->body($this->detail($id)); } /** * Edit interface. * * @param mixed $id * @param Content $content * @return Content */ public function edit($id, Content $content) { return $content ->header('试题管理') ->description('编辑') ->body($this->form()->edit($id)); } /** * Create interface. * * @param Content $content * @return Content */ public function create(Content $content) { return $content ->header('试题管理') ->description('创建') ->body($this->form()); } /** * Make a grid builder. * * @return Grid */ protected function grid() { $grid = new Grid(new Question); $grid->model()->orderBy('id', 'desc'); $grid->tools(function ($tools) { $tools->append(new QuestionImport()); }); $grid->id('编号'); $grid->name('题目名称'); $grid->type('题目类型')->label(); $grid->category('试题位置')->using(Question::$categoryMap); $grid->options('题目选项')->display(function ($options) { $str = ''; foreach ($options as $option) { $str .= "{$option['name']}:{$option['val']}
"; } return $str; }); $grid->answers('题目答案')->label('default'); $grid->mark('分值'); $grid->updated_at('更新时间'); $grid->actions(function (Grid\Displayers\Actions $actions) { $actions->disableView(); }); $grid->filter(function (Grid\Filter $filter) { $filter->disableIdFilter(); $filter->like('name', '题目'); $options = Question::distinct()->pluck('type', 'type'); $filter->in('type', '题目类型')->multipleSelect($options); }); $grid->disableExport(); return $grid; } /** * Make a show builder. * * @param mixed $id * @return Show */ protected function detail($id) { $show = new Show(Question::findOrFail($id)); $show->id('编号'); $show->name('题目名称'); $show->options('题目选项'); $show->answers('题目答案'); $show->radio('是否多选'); $show->type('类型'); $show->created_at('创建时间'); $show->updated_at('更新时间'); return $show; } /** * Make a form builder. * * @return Form */ protected function form() { $form = new Form(new Question); $form->text('name', '题目名称')->rules('required'); $form->question('options', '试题'); $form->select('category', '试题位置')->options(Question::$categoryMap)->default(Question::CATEGORY_TEST); // $form->textarea('options', '题目选项')->help("输入题目选项并且以换行符分开用选项用大写字母排序 A."); $form->multipleSelect('answers', '题目答案')->options(['A' => 'A', 'B' => 'B', 'C' => 'C', 'D' => 'D', 'E' => 'E', 'F' => 'F', 'G' => 'G'])->rules('required'); // $form->text('answers', '题目答案')->help("题目答案用大写字母多选题用逗号隔开如A,B"); // $form->switch('radio', '是否多选'); $form->text('type', '题目类型')->rules('required'); $form->text('mark', '题目分值')->default(10)->rules('required'); $form->textarea('analysis', '解析'); $form->disableViewCheck(); $form->disableEditingCheck(); $form->disableCreatingCheck(); return $form; } }