AdminController.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. namespace Dcat\Admin\Controllers;
  3. use Dcat\Admin\Layout\Content;
  4. use Illuminate\Routing\Controller;
  5. class AdminController extends Controller
  6. {
  7. use HasResourceActions;
  8. /**
  9. * Title for current resource.
  10. *
  11. * @var string
  12. */
  13. protected $title = '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;
  33. }
  34. /**
  35. * Index interface.
  36. *
  37. * @param Content $content
  38. *
  39. * @return Content
  40. */
  41. public function index(Content $content)
  42. {
  43. return $content
  44. ->title($this->title())
  45. ->description($this->description['index'] ?? trans('admin.list'))
  46. ->body($this->grid());
  47. }
  48. /**
  49. * Show interface.
  50. *
  51. * @param mixed $id
  52. * @param Content $content
  53. *
  54. * @return Content
  55. */
  56. public function show($id, Content $content)
  57. {
  58. return $content
  59. ->title($this->title())
  60. ->description($this->description['show'] ?? trans('admin.show'))
  61. ->body($this->detail($id));
  62. }
  63. /**
  64. * Edit interface.
  65. *
  66. * @param mixed $id
  67. * @param Content $content
  68. *
  69. * @return Content
  70. */
  71. public function edit($id, Content $content)
  72. {
  73. return $content
  74. ->title($this->title())
  75. ->description($this->description['edit'] ?? trans('admin.edit'))
  76. ->body($this->form()->edit($id));
  77. }
  78. /**
  79. * Create interface.
  80. *
  81. * @param Content $content
  82. *
  83. * @return Content
  84. */
  85. public function create(Content $content)
  86. {
  87. return $content
  88. ->title($this->title())
  89. ->description($this->description['create'] ?? trans('admin.create'))
  90. ->body($this->form());
  91. }
  92. }