DocterTypeController.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. namespace App\Admin\Controllers;
  3. use App\Models\DocterType;
  4. use Encore\Admin\Controllers\AdminController;
  5. use Encore\Admin\Form;
  6. use Encore\Admin\Grid;
  7. use Encore\Admin\Show;
  8. class DocterTypeController extends AdminController
  9. {
  10. /**
  11. * Title for current resource.
  12. *
  13. * @var string
  14. */
  15. protected $title = '医生类型';
  16. /**
  17. * Make a grid builder.
  18. *
  19. * @return Grid
  20. */
  21. protected function grid()
  22. {
  23. $grid = new Grid(new DocterType());
  24. $grid->filter(function ($filter){
  25. $filter->disableIdFilter();
  26. $filter->like('name','名称');
  27. });
  28. $grid->column('id', __('ID'));
  29. $grid->column('name', __('名称'));
  30. $states = [
  31. 'off' => ['value' => 0, 'text' => '关闭', 'color' => 'danger'],
  32. 'on' => ['value' => 1, 'text' => '打开', 'color' => 'success'],
  33. ];
  34. $grid->column('status', __('状态'))->switch($states);
  35. $grid->column('created_at', __('创建时间'));
  36. $grid->column('updated_at', __('更新时间'));
  37. $grid->actions(function($actions){
  38. $actions->disableDelete();
  39. });
  40. return $grid;
  41. }
  42. /**
  43. * Make a show builder.
  44. *
  45. * @param mixed $id
  46. * @return Show
  47. */
  48. protected function detail($id)
  49. {
  50. $show = new Show(DocterType::findOrFail($id));
  51. $show->field('id', __('Id'));
  52. $show->field('name', __('名称'));
  53. $show->field('status', __('启用禁用'));
  54. $show->field('created_at', __('创建时间'));
  55. $show->field('updated_at', __('更新时间'));
  56. return $show;
  57. }
  58. /**
  59. * Make a form builder.
  60. *
  61. * @return Form
  62. */
  63. protected function form()
  64. {
  65. $form = new Form(new DocterType());
  66. $form->text('name', __('名称'));
  67. $states = [
  68. 'off' => ['value' => 0, 'text' => '关闭', 'color' => 'danger'],
  69. 'on' => ['value' => 1, 'text' => '打开', 'color' => 'success'],
  70. ];
  71. $form->switch('status', __('名称'))->states($states);
  72. $form->tools(function (Form\Tools $tools) {
  73. $tools->disableDelete();
  74. $tools->disableView();
  75. });
  76. $form->disableEditingCheck();
  77. $form->disableCreatingCheck();
  78. $form->disableViewCheck();
  79. return $form;
  80. }
  81. }