UserController.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <?php
  2. namespace App\Admin\Controllers;
  3. use App\Model\User;
  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 UserController 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('Index')
  23. ->description('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('Detail')
  37. ->description('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('Edit')
  51. ->description('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('Create')
  64. ->description('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 User);
  75. $grid->user_id('User id');
  76. $grid->name('Name');
  77. $grid->avatar('Avatar');
  78. $grid->cmcc_id('Cmcc id');
  79. $grid->mt('Mt');
  80. $grid->win_count('Win count');
  81. $grid->lose_count('Lose count');
  82. $grid->is_login('Is login');
  83. $grid->is_robot('Is robot');
  84. $grid->client_id('Client id');
  85. $grid->created_at('Created at');
  86. $grid->updated_at('Updated at');
  87. $grid->deleted_at('Deleted at');
  88. return $grid;
  89. }
  90. /**
  91. * Make a show builder.
  92. *
  93. * @param mixed $id
  94. * @return Show
  95. */
  96. protected function detail($id)
  97. {
  98. $show = new Show(User::findOrFail($id));
  99. $show->user_id('User id');
  100. $show->name('Name');
  101. $show->avatar('Avatar');
  102. $show->cmcc_id('Cmcc id');
  103. $show->mt('Mt');
  104. $show->win_count('Win count');
  105. $show->lose_count('Lose count');
  106. $show->is_login('Is login');
  107. $show->is_robot('Is robot');
  108. $show->client_id('Client id');
  109. $show->created_at('Created at');
  110. $show->updated_at('Updated at');
  111. $show->deleted_at('Deleted at');
  112. return $show;
  113. }
  114. /**
  115. * Make a form builder.
  116. *
  117. * @return Form
  118. */
  119. protected function form()
  120. {
  121. $form = new Form(new User);
  122. $form->text('name', 'Name');
  123. $form->image('avatar', 'Avatar');
  124. $form->text('cmcc_id', 'Cmcc id');
  125. $form->text('mt', 'Mt');
  126. $form->number('win_count', 'Win count');
  127. $form->number('lose_count', 'Lose count');
  128. $form->switch('is_login', 'Is login');
  129. $form->switch('is_robot', 'Is robot');
  130. $form->text('client_id', 'Client id');
  131. return $form;
  132. }
  133. }