AdminController.php 3.0 KB

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