AdminController.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <?php
  2. namespace Dcat\Admin\Controllers;
  3. use Dcat\Admin\IFrameGrid;
  4. use Dcat\Admin\Layout\Content;
  5. use Illuminate\Routing\Controller;
  6. class AdminController extends Controller
  7. {
  8. /**
  9. * Title for current resource.
  10. *
  11. * @var string
  12. */
  13. protected $title;
  14. /**
  15. * Set description for following 4 action pages.
  16. *
  17. * @var array
  18. */
  19. protected $description = [
  20. // 'index' => 'Index',
  21. // 'show' => 'Show',
  22. // 'edit' => 'Edit',
  23. // 'create' => 'Create',
  24. ];
  25. /**
  26. * Get content title.
  27. *
  28. * @return string
  29. */
  30. protected function title()
  31. {
  32. return $this->title ?: admin_trans_label();
  33. }
  34. /**
  35. * Get description for following 4 action pages.
  36. *
  37. * @return array
  38. */
  39. protected function description()
  40. {
  41. return $this->description;
  42. }
  43. /**
  44. * Index interface.
  45. *
  46. * @param Content $content
  47. *
  48. * @return Content
  49. */
  50. public function index(Content $content)
  51. {
  52. if (request(IFrameGrid::QUERY_NAME)) {
  53. return $content->body($this->iFrameGrid());
  54. }
  55. return $content
  56. ->title($this->title())
  57. ->description($this->description()['index'] ?? trans('admin.list'))
  58. ->perfectScrollbar()
  59. ->body($this->grid());
  60. }
  61. /**
  62. * Show interface.
  63. *
  64. * @param mixed $id
  65. * @param Content $content
  66. *
  67. * @return Content
  68. */
  69. public function show($id, Content $content)
  70. {
  71. return $content
  72. ->title($this->title())
  73. ->description($this->description()['show'] ?? trans('admin.show'))
  74. ->perfectScrollbar()
  75. ->body($this->detail($id));
  76. }
  77. /**
  78. * Edit interface.
  79. *
  80. * @param mixed $id
  81. * @param Content $content
  82. *
  83. * @return Content
  84. */
  85. public function edit($id, Content $content)
  86. {
  87. return $content
  88. ->title($this->title())
  89. ->description($this->description()['edit'] ?? trans('admin.edit'))
  90. ->body($this->form()->edit($id));
  91. }
  92. /**
  93. * Create interface.
  94. *
  95. * @param Content $content
  96. *
  97. * @return Content
  98. */
  99. public function create(Content $content)
  100. {
  101. return $content
  102. ->title($this->title())
  103. ->description($this->description()['create'] ?? trans('admin.create'))
  104. ->body($this->form());
  105. }
  106. /**
  107. * Update the specified resource in storage.
  108. *
  109. * @param int $id
  110. *
  111. * @return \Illuminate\Http\Response
  112. */
  113. public function update($id)
  114. {
  115. return $this->form()->update($id);
  116. }
  117. /**
  118. * Store a newly created resource in storage.
  119. *
  120. * @return mixed
  121. */
  122. public function store()
  123. {
  124. return $this->form()->store();
  125. }
  126. /**
  127. * Remove the specified resource from storage.
  128. *
  129. * @param int $id
  130. *
  131. * @return \Illuminate\Http\Response
  132. */
  133. public function destroy($id)
  134. {
  135. return $this->form()->destroy($id);
  136. }
  137. }