SchoolController.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <?php
  2. namespace App\Admin\Controllers;
  3. use App\School;
  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 SchoolController 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->form()->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 School);
  75. $grid->id("编号");
  76. $grid->name('学校全名');
  77. $grid->address('地址');
  78. $grid->nickname('简称');
  79. $grid->sclass("班级数量")->display(function ($sclass) {
  80. $count = count($sclass);
  81. return "<span class='label label-warning'>{$count}</span>";
  82. });
  83. $grid->disableExport();
  84. $grid->actions(function (Grid\Displayers\Actions $actions) {
  85. $actions->disableView();
  86. });
  87. return $grid;
  88. }
  89. /**
  90. * Make a show builder.
  91. *
  92. * @param mixed $id
  93. * @return Show
  94. */
  95. protected function detail($id)
  96. {
  97. $show = new Show(School::findOrFail($id));
  98. $show->id('编号');
  99. $show->name('学校全名');
  100. $show->address('地址');
  101. $show->nickname('简称');
  102. $show->created_at('创建时间');
  103. $show->updated_at('更新时间');
  104. return $show;
  105. }
  106. /**
  107. * Make a form builder.
  108. *
  109. * @return Form
  110. */
  111. protected function form()
  112. {
  113. $form = new Form(new School);
  114. $form->text('name', '学校全名');
  115. $form->text('address', '学校地址');
  116. $form->text('nickname', '学校简称');
  117. $form->disableViewCheck();
  118. $form->disableEditingCheck();
  119. $form->disableCreatingCheck();
  120. $form->tools(function (Form\Tools $tools) {
  121. $tools->disableView();
  122. });
  123. return $form;
  124. }
  125. }