123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- <?php
- namespace App\Admin\Controllers;
- use App\Models\Scale;
- use Encore\Admin\Controllers\AdminController;
- use Encore\Admin\Form;
- use Encore\Admin\Grid;
- use Encore\Admin\Show;
- use App\Models\ScaleCategory;
- use App\Models\ThirdScale;
- use Illuminate\Http\Request;
- class ScaleController extends AdminController
- {
- /**
- * Title for current resource.
- *
- * @var string
- */
- // protected $title = '量表内容';
- protected $title = '心理评估内容';
- /**
- * Make a grid builder.
- *
- * @return Grid
- */
- protected function grid()
- {
- $grid = new Grid(new Scale());
- $grid->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();
- }
- }
|