PolicyPropertyController.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <?php
  2. namespace App\Admin\Controllers\Content;
  3. use App\Models\PolicyProperty;
  4. use App\Http\Controllers\Controller;
  5. use Encore\Admin\Controllers\HasResourceActions;
  6. use Encore\Admin\Form;
  7. use Encore\Admin\Grid;
  8. use Encore\Admin\Layout\Content;
  9. use Encore\Admin\Show;
  10. class PolicyPropertyController extends Controller
  11. {
  12. use HasResourceActions;
  13. /**
  14. * Index interface.
  15. *
  16. * @param Content $content
  17. * @return Content
  18. */
  19. public function index(Content $content)
  20. {
  21. return $content
  22. ->header('政策层次')
  23. ->description('分类信息谨慎修改,如需修改请提前咨询系统客服。')
  24. ->body($this->grid());
  25. }
  26. /**
  27. * Show interface.
  28. *
  29. * @param mixed $id
  30. * @param Content $content
  31. * @return Content
  32. */
  33. public function show($id, Content $content)
  34. {
  35. return $content
  36. ->header('政策层次')
  37. ->description('分类信息谨慎修改,如需修改请提前咨询系统客服。')
  38. ->body($this->detail($id));
  39. }
  40. /**
  41. * Edit interface.
  42. *
  43. * @param mixed $id
  44. * @param Content $content
  45. * @return Content
  46. */
  47. public function edit($id, Content $content)
  48. {
  49. return $content
  50. ->header('政策层次')
  51. ->description('分类信息谨慎修改,如需修改请提前咨询系统客服。')
  52. ->body($this->editForm()->edit($id));
  53. }
  54. /**
  55. * Create interface.
  56. *
  57. * @param Content $content
  58. * @return Content
  59. */
  60. public function create(Content $content)
  61. {
  62. return $content
  63. ->header('政策层次')
  64. ->description('分类信息谨慎修改,如需修改请提前咨询系统客服。')
  65. ->body($this->form());
  66. }
  67. /**
  68. * Make a grid builder.
  69. *
  70. * @return Grid
  71. */
  72. protected function grid()
  73. {
  74. $grid = new Grid(new PolicyProperty);
  75. $grid->id('id');
  76. $grid->categoryname('名称');
  77. $grid->admin_set('类型')->display(function ($admin_set) {
  78. if ($admin_set == 1) {
  79. return '系统分类';
  80. }else{
  81. return '自定义分类 ';
  82. }
  83. });
  84. $grid->category_order('排序');
  85. $grid->disableCreateButton(false);
  86. $grid->actions(function ($actions) {
  87. $actions->disableEdit(false);
  88. $actions->disableDelete(false);
  89. });
  90. $grid->filter(function ($filter) {
  91. $filter->like('categoryname', '名称');
  92. });
  93. return $grid;
  94. }
  95. /**
  96. * Make a show builder.
  97. *
  98. * @param mixed $id
  99. * @return Show
  100. */
  101. protected function detail($id)
  102. {
  103. $show = new Show(PolicyProperty::findOrFail($id));
  104. $show->id('ID');
  105. $show->created_at('Created at');
  106. $show->updated_at('Updated at');
  107. return $show;
  108. }
  109. /**
  110. * Make a form builder.
  111. *
  112. * @return Form
  113. */
  114. protected function form()
  115. {
  116. $form = new Form(new PolicyProperty);
  117. $form->text('categoryname', '名称');
  118. $form->number('category_order', '排序')->default(0)->min(0);
  119. $form->hidden('admin_set')->value(0);
  120. return $form;
  121. }
  122. public function update($id)
  123. {
  124. return $this->editForm()->update($id);
  125. }
  126. protected function editForm()
  127. {
  128. $form = new Form(new PolicyProperty);
  129. $form->text('categoryname', '名称');
  130. $form->number('category_order', '排序')->default(0)->min(0);
  131. return $form;
  132. }
  133. }