JobfairManagementController.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. <?php
  2. namespace App\Admin\Controllers\Jobfair;
  3. use App\Http\Controllers\Controller;
  4. use App\Models\Jobfair\JobfairManagement;
  5. use Encore\Admin\Controllers\HasResourceActions;
  6. use Encore\Admin\Facades\Admin;
  7. use Encore\Admin\Form;
  8. use Encore\Admin\Grid;
  9. use Encore\Admin\Layout\Content;
  10. use Encore\Admin\Show;
  11. class JobfairManagementController extends Controller
  12. {
  13. use HasResourceActions;
  14. /**
  15. * Index interface.
  16. *
  17. * @param Content $content
  18. * @return Content
  19. */
  20. public function index(Content $content)
  21. {
  22. return $content
  23. ->header('招聘会分类')
  24. ->description('')
  25. ->body($this->grid());
  26. }
  27. /**
  28. * Show interface.
  29. *
  30. * @param mixed $id
  31. * @param Content $content
  32. * @return Content
  33. */
  34. public function show($id, Content $content)
  35. {
  36. return $content
  37. ->header('招聘会分类详情')
  38. ->description('')
  39. ->body($this->detail($id));
  40. }
  41. /**
  42. * Edit interface.
  43. *
  44. * @param mixed $id
  45. * @param Content $content
  46. * @return Content
  47. */
  48. public function edit($id, Content $content)
  49. {
  50. return $content
  51. ->header('招聘会分类编辑')
  52. ->description('')
  53. ->body($this->editForm()->edit($id));
  54. }
  55. /**
  56. * Create interface.
  57. *
  58. * @param Content $content
  59. * @return Content
  60. */
  61. public function create(Content $content)
  62. {
  63. return $content
  64. ->header('招聘会分类创建')
  65. ->description('')
  66. ->body($this->createForm());
  67. }
  68. /**
  69. * Make a grid builder.
  70. *
  71. * @return Grid
  72. */
  73. protected function grid()
  74. {
  75. $grid = new Grid(new JobfairManagement);
  76. $grid->model()->orderBy('id', 'desc');
  77. $grid->name('名称')->width(200);
  78. $grid->created_at('创建时间');
  79. $grid->updated_at('更新时间');
  80. $grid->actions(function ($actions) use ($grid) {
  81. if (Admin::user()->can('jobfair_type_manager_edit')) {
  82. $actions->disableEdit(false);
  83. }
  84. if (Admin::user()->can('jobfair_type_manager_delete')) {
  85. $actions->disableDelete(false);
  86. }
  87. });
  88. if (Admin::user()->can('jobfair_type_manager_delete')) {
  89. $grid->tools(function ($tools) {
  90. $tools->batch(function ($batch) {
  91. $batch->disableDelete(false);
  92. });
  93. });
  94. $grid->disableRowSelector(false);
  95. }
  96. $grid->filter(function ($filter) {
  97. $filter->like('name', '分类名称');
  98. });
  99. if (Admin::user()->can('jobfair_type_manager_create')) {
  100. $grid->disableCreateButton(false);
  101. }
  102. return $grid;
  103. }
  104. /**
  105. * Make a show builder.
  106. *
  107. * @param mixed $id
  108. * @return Show
  109. */
  110. protected function detail($id)
  111. {
  112. $show = new Show(JobfairManagement::findOrFail($id));
  113. $show->id('ID');
  114. $show->name('名称');
  115. $show->created_at('创建时间');
  116. $show->updated_at('更新时间');
  117. return $show;
  118. }
  119. /**
  120. * Make a form builder.
  121. *
  122. * @return Form
  123. */
  124. protected function form()
  125. {
  126. $form = new Form(new JobfairManagement);
  127. $form->display('ID');
  128. $form->display('Created at');
  129. $form->display('Updated at');
  130. return $form;
  131. }
  132. /**
  133. * Make a form builder.
  134. *
  135. * @return Form
  136. */
  137. protected function editForm()
  138. {
  139. $form = new Form(new JobfairManagement);
  140. $form->text('name', '名称')->rules([
  141. 'required',
  142. ]);
  143. $form->number('order_list', '排序')->min(0)->help('数字越大,越靠前!');
  144. return $form;
  145. }
  146. protected function createForm()
  147. {
  148. $form = new Form(new JobfairManagement);
  149. $form->text('name', '名称')->rules([
  150. 'required',
  151. ])->setMustMark();
  152. $form->number('order_list', '排序')->min(0)->help('数字越大,越靠前!');
  153. return $form;
  154. }
  155. /**
  156. * Store a newly created resource in storage.
  157. *
  158. * @return mixed
  159. */
  160. public function store()
  161. {
  162. return $this->createForm()->store();
  163. }
  164. /**
  165. * Update the specified resource in storage.
  166. *
  167. * @param int $id
  168. *
  169. * @return \Illuminate\Http\Response|\Symfony\Component\HttpFoundation\Response
  170. */
  171. public function update($id)
  172. {
  173. return $this->editForm()->update($id);
  174. }
  175. }