ControllerHasTab.php 860 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. namespace App\Traits;
  3. use Dcat\Admin\Grid;
  4. use Dcat\Admin\Layout\Content;
  5. use Illuminate\Contracts\Translation\Translator;
  6. trait ControllerHasTab
  7. {
  8. /**
  9. * 列表页面布局.
  10. * @param Content $content
  11. * @return Content
  12. */
  13. public function index(Content $content): Content
  14. {
  15. return $content
  16. ->title($this->title())
  17. ->description(admin_trans_label('description'))
  18. ->body($this->tab($this->renderGrid()));
  19. }
  20. /**
  21. * 标题.
  22. * @return array|Translator|string|null
  23. */
  24. public function title(): array|string|Translator|null
  25. {
  26. return admin_trans_label('title');
  27. }
  28. /**
  29. * 默认渲染grid.
  30. * @return \Dcat\Admin\Grid|\App\Grid
  31. */
  32. public function renderGrid(): Grid|\App\Grid
  33. {
  34. return $this->grid();
  35. }
  36. }