RestRoomController.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <?php
  2. namespace App\Admin\Controllers;
  3. use App\rest_room;
  4. use App\code;
  5. use Encore\Admin\Auth\Database\Administrator;
  6. use Encore\Admin\Form;
  7. use Encore\Admin\Grid;
  8. use Encore\Admin\Facades\Admin;
  9. use Encore\Admin\Layout\Content;
  10. use App\Http\Controllers\Controller;
  11. use Encore\Admin\Controllers\ModelForm;
  12. class RestRoomController extends Controller
  13. {
  14. use ModelForm;
  15. /**
  16. * Index interface.
  17. *
  18. * @return Content
  19. */
  20. public function index()
  21. {
  22. return Admin::content(function (Content $content) {
  23. $content->header('厕所管理');
  24. $content->description('列表');
  25. $content->body($this->grid());
  26. });
  27. }
  28. /**
  29. * Edit interface.
  30. *
  31. * @param $id
  32. * @return Content
  33. */
  34. public function edit($id)
  35. {
  36. return Admin::content(function (Content $content) use ($id) {
  37. $content->header('厕所管理');
  38. $content->description('编辑');
  39. $content->body($this->form()->edit($id));
  40. });
  41. }
  42. /**
  43. * Create interface.
  44. *
  45. * @return Content
  46. */
  47. public function create()
  48. {
  49. return Admin::content(function (Content $content) {
  50. $content->header('厕所管理');
  51. $content->description('新增');
  52. $content->body($this->form());
  53. });
  54. }
  55. /**
  56. * Make a grid builder.
  57. *
  58. * @return Grid
  59. */
  60. protected function grid()
  61. {
  62. return Admin::grid(rest_room::class, function (Grid $grid) {
  63. $grid->id('序号')->sortable();
  64. $grid->open_status('开放状态')->switch([
  65. 'on' => ['value' => 1, 'text' => '开放', 'color' => 'success'],
  66. 'off' => ['value' => 0, 'text' => '关闭', 'color' => 'default'],
  67. ]);;
  68. $grid->column('number', '编号');
  69. $grid->column('name', '名称');
  70. $grid->column('address', '位置');
  71. $grid->serve_people_facility( '便民设施')->display(function ($value){
  72. $name = code::whereIn('id',$value)->pluck('code_dsp_name_cn');
  73. return $name;
  74. })->label();
  75. $grid->column('create_id', '创建者')->display(function ($value){
  76. $name = Administrator::where('id',$value)->pluck('name')->first();
  77. return $name;
  78. });
  79. $grid->column('update_id', '更新者')->display(function ($value){
  80. $name = Administrator::where('id',$value)->pluck('name')->first();
  81. return $name;
  82. });;
  83. $grid->created_at('创建时间');
  84. $grid->updated_at('修改时间');
  85. $grid->disableExport();
  86. });
  87. }
  88. /**
  89. * Make a form builder.
  90. *
  91. * @return Form
  92. */
  93. protected function form()
  94. {
  95. return Admin::form(rest_room::class, function (Form $form) {
  96. $form->display('id', '序号');
  97. $form->text('number','编号')->rules('required|max:10');
  98. $form->text('name','名称')->rules('required|max:10');
  99. $form->text('address','位置')->rules('required|max:30');
  100. $form->text('poi_name','POI名称')->rules('required|max:20');
  101. $form->image('poi_icon','POI图标')->uniqueName();
  102. $form->url('poi_link_url','POI跳转链接');
  103. $form->text('poi_x_coord','POI X坐标')->rules('required|max:20');
  104. $form->text('poi_y_coord','POI Y坐标')->rules('required|max:20');
  105. $form->checkbox('serve_people_facility','便民设施')->options(code::where('type_id',6)->pluck('code_dsp_name_cn','id'));
  106. $form->switch('open_status','开放状态')->states([
  107. 'on' => ['value' => 1, 'text' => '开放', 'color' => 'success'],
  108. 'off' => ['value' => 0, 'text' => '关闭', 'color' => 'default'],
  109. ])->default(1);
  110. $form->display('update_id', '更新者')->with(function ($value){
  111. if($value){
  112. }else{
  113. $value=Admin::user()->id;
  114. }
  115. $name = Administrator::where('id',$value)->pluck('name')->first();
  116. return $name;
  117. });
  118. $form->display('create_id', '创建者')->with(function ($value){
  119. if($value){
  120. }else{
  121. $value=Admin::user()->id;
  122. }
  123. $name = Administrator::where('id',$value)->pluck('name')->first();
  124. return $name;
  125. });
  126. $form->hidden('create_id')->default(Admin::user()->id);
  127. //保存前回调
  128. $form->saving(function (Form $form) {
  129. $form->update_id =Admin::user()->id;
  130. });
  131. $form->display('created_at', '创建时间');
  132. $form->display('updated_at', '更新时间');
  133. });
  134. }
  135. }