AdminController.php 3.3 KB

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