AdminController.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <?php
  2. namespace Dcat\Admin\Controllers;
  3. use Dcat\Admin\Grid;
  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(Grid::IFRAME_QUERY_NAME)) {
  53. if (method_exists($this, 'iframe')) {
  54. return $content->full()->body($this->iframe());
  55. }
  56. return $content->full()->body($this->iFrameGrid());
  57. }
  58. return $content
  59. ->title($this->title())
  60. ->description($this->description()['index'] ?? trans('admin.list'))
  61. ->body($this->grid());
  62. }
  63. /**
  64. * Show interface.
  65. *
  66. * @param mixed $id
  67. * @param Content $content
  68. *
  69. * @return Content
  70. */
  71. public function show($id, Content $content)
  72. {
  73. return $content
  74. ->title($this->title())
  75. ->description($this->description()['show'] ?? trans('admin.show'))
  76. ->body($this->detail($id));
  77. }
  78. /**
  79. * Edit interface.
  80. *
  81. * @param mixed $id
  82. * @param Content $content
  83. *
  84. * @return Content
  85. */
  86. public function edit($id, Content $content)
  87. {
  88. return $content
  89. ->title($this->title())
  90. ->description($this->description()['edit'] ?? trans('admin.edit'))
  91. ->body($this->form()->edit($id));
  92. }
  93. /**
  94. * Create interface.
  95. *
  96. * @param Content $content
  97. *
  98. * @return Content
  99. */
  100. public function create(Content $content)
  101. {
  102. return $content
  103. ->title($this->title())
  104. ->description($this->description()['create'] ?? trans('admin.create'))
  105. ->body($this->form());
  106. }
  107. /**
  108. * Update the specified resource in storage.
  109. *
  110. * @param int $id
  111. *
  112. * @return \Illuminate\Http\Response
  113. */
  114. public function update($id)
  115. {
  116. return $this->form()->update($id);
  117. }
  118. /**
  119. * Store a newly created resource in storage.
  120. *
  121. * @return mixed
  122. */
  123. public function store()
  124. {
  125. return $this->form()->store();
  126. }
  127. /**
  128. * Remove the specified resource from storage.
  129. *
  130. * @param int $id
  131. *
  132. * @return \Illuminate\Http\Response
  133. */
  134. public function destroy($id)
  135. {
  136. return $this->form()->destroy($id);
  137. }
  138. }