CompanyTplController.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <?php
  2. namespace App\Admin\Controllers\Company;
  3. use App\Http\Controllers\Controller;
  4. use App\Models\CompanyTpl;
  5. use App\Models\Tpl;
  6. use Encore\Admin\Controllers\HasResourceActions;
  7. use Encore\Admin\Form;
  8. use Encore\Admin\Grid;
  9. use Encore\Admin\Layout\Content;
  10. use Encore\Admin\Show;
  11. class CompanyTplController 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. ->body(view('admin.companytpl.index')->with('grid', $this->grid()));
  27. }
  28. /**
  29. * Show interface.
  30. *
  31. * @param mixed $id
  32. * @param Content $content
  33. * @return Content
  34. */
  35. public function show($id, Content $content)
  36. {
  37. return $content
  38. ->header('Detail')
  39. ->description('description')
  40. ->body($this->detail($id));
  41. }
  42. /**
  43. * Edit interface.
  44. *
  45. * @param mixed $id
  46. * @param Content $content
  47. * @return Content
  48. */
  49. public function edit($id, Content $content)
  50. {
  51. return $content
  52. ->header('企业模版')
  53. ->description('编辑')
  54. // ->body($this->form()->edit($id));
  55. ->body(view('admin.companytpl.edit')->with('form', $this->editForm()->edit($id)->render()));
  56. }
  57. /**
  58. * Create interface.
  59. *
  60. * @param Content $content
  61. * @return Content
  62. */
  63. public function create(Content $content)
  64. {
  65. return $content
  66. ->header('Create')
  67. ->description('description')
  68. ->body($this->form());
  69. }
  70. /**
  71. * Make a grid builder.
  72. *
  73. * @return Grid
  74. */
  75. protected function grid()
  76. {
  77. $grid = new Grid(new CompanyTpl);
  78. $grid->id('ID');
  79. $grid->column('companys.companyname', '企业名称');
  80. $grid->column('companys.username', '用户名称');
  81. $grid->column('tpls.images', '缩略图')->image();
  82. $grid->created_at('添加时间');
  83. $grid->actions(function ($actions) {
  84. $actions->disableView();
  85. });
  86. $grid->filter(function ($filter) {
  87. $filter->equal('uid', '企业ID');
  88. $filter->equal('tplid', '模版ID');
  89. $filter->like('companys.companyname', '企业名称');
  90. $filter->like('companys.username', '用户名称');
  91. });
  92. return $grid;
  93. }
  94. /**
  95. * Make a show builder.
  96. *
  97. * @param mixed $id
  98. * @return Show
  99. */
  100. protected function detail($id)
  101. {
  102. $show = new Show(CompanyTpl::findOrFail($id));
  103. $show->id('ID');
  104. $show->created_at('Created at');
  105. $show->updated_at('Updated at');
  106. return $show;
  107. }
  108. /**
  109. * Make a form builder.
  110. *
  111. * @return Form
  112. */
  113. protected function form()
  114. {
  115. $form = new Form(new CompanyTpl);
  116. $form->display('ID');
  117. $form->display('Created at');
  118. $form->display('Updated at');
  119. return $form;
  120. }
  121. protected function editForm()
  122. {
  123. $form = new Form(new CompanyTpl);
  124. $form->display('companys.username', '用户名');
  125. $form->display('uid', '用户ID');
  126. $form->display('tplid', '模版ID');
  127. $form->file('tpls.images', '缩略图')->disable();
  128. $form->tools(function ($tools) {
  129. $tools->disableView();
  130. });
  131. $form->builder(function (Form $form) {
  132. $form = new Form(new Tpl);
  133. dd($form);
  134. });
  135. return $form;
  136. }
  137. }