ScaleCategoryController.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. namespace App\Admin\Controllers;
  3. use App\Admin\Controllers\RowAction\CustomAction;
  4. use App\Models\ScaleCategory;
  5. use Encore\Admin\Controllers\AdminController;
  6. use Encore\Admin\Form;
  7. use Encore\Admin\Grid;
  8. use Encore\Admin\Show;
  9. /**
  10. * 量表分类,控制器
  11. */
  12. class ScaleCategoryController extends AdminController
  13. {
  14. /**
  15. * Title for current resource.
  16. *
  17. * @var string
  18. */
  19. // protected $title = '量表分类';
  20. protected $title = '心理评估分类';
  21. /**
  22. * Make a grid builder.
  23. *
  24. * @return Grid
  25. */
  26. protected function grid()
  27. {
  28. $grid = new Grid(new ScaleCategory());
  29. // // 禁用创建按钮
  30. // $grid->disableCreateButton();
  31. // // 禁用编辑功能
  32. // $grid->disableActions();
  33. // 新增过滤筛选
  34. $grid->filter(function ($filter) {
  35. $filter->like('name', '分类名称');
  36. $filter->like('info', '分类首页简介');
  37. $filter->like('list_info', __('分类列表简介'));
  38. });
  39. $grid->column('id', __('Id'));
  40. $grid->column('name', __('分类名称'));
  41. $grid->column('info', __('分类首页简介'));
  42. $grid->column('list_info', __('分类列表简介'));
  43. $grid->column('rank', __('排序 越大越前'));
  44. $grid->column('is_index', __('是否首页'))->display(function ($isIndex){
  45. return isset(ScaleCategory::isIndexMap[$isIndex])
  46. ?
  47. ScaleCategory::isIndexMap[$isIndex]
  48. :
  49. ""
  50. ;
  51. });
  52. $grid->column('created_at', __('创建时间'));
  53. $grid->column('updated_at', __('更新时间'));
  54. return $grid;
  55. }
  56. /**
  57. * Make a show builder.
  58. *
  59. * @param mixed $id
  60. * @return Show
  61. */
  62. protected function detail($id)
  63. {
  64. $show = new Show(ScaleCategory::findOrFail($id));
  65. $show->field('id', __('Id'));
  66. $show->field('name', __('Name'));
  67. $show->field('info', __('Info'));
  68. $show->field('list_info', __('List Info'));
  69. $show->field('pic', __('Pic'));
  70. $show->field('rank', __('Rank'));
  71. $show->field('created_at', __('Created at'));
  72. $show->field('updated_at', __('Updated at'));
  73. $show->field('deleted_at', __('Deleted at'));
  74. return $show;
  75. }
  76. /**
  77. * Make a form builder.
  78. *
  79. * @return Form
  80. */
  81. protected function form()
  82. {
  83. $form = new Form(new ScaleCategory());
  84. $form->text('name', __('分类名称'));
  85. $form->text('info', __('分类首页简介'));
  86. $form->select('pid', __('上级分类'))->options(ScaleCategory::where('deleted_at', null)->pluck('name', 'id'))->default(0);
  87. $form->text('list_info', __('分类列表简介'));
  88. $form->image('pic', __('首页图片'));
  89. $form->image('pic2', __('分类图片'));
  90. $form->number('rank', __('排序 越大越前'));
  91. $form->radio("is_index","是否首页")
  92. ->options(ScaleCategory::isIndexMap)
  93. ->default(ScaleCategory::isIndexNo)
  94. ;
  95. return $form;
  96. }
  97. }