AdminController.php 2.9 KB

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