HasTabs.php 853 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace Dcat\Admin\Form\Concerns;
  3. use Closure;
  4. use Dcat\Admin\Form\Tab;
  5. trait HasTabs
  6. {
  7. /**
  8. * @var Tab
  9. */
  10. protected $tab = null;
  11. /**
  12. * Use tab to split form.
  13. *
  14. * @param string $title
  15. * @param Closure $content
  16. * @param bool $active
  17. * @param string|null $id
  18. * @return $this
  19. */
  20. public function tab($title, Closure $content, $active = false, ?string $id = null)
  21. {
  22. $this->getTab()->append($title, $content, $active, $id);
  23. return $this;
  24. }
  25. public function hasTab()
  26. {
  27. return $this->tab ? true : false;
  28. }
  29. /**
  30. * Get Tab instance.
  31. *
  32. * @return Tab
  33. */
  34. public function getTab()
  35. {
  36. if (is_null($this->tab)) {
  37. $this->tab = new Tab($this);
  38. }
  39. return $this->tab;
  40. }
  41. }