add($items); $this->class('nav nav-pills nav-stacked'); $this->id('nav-list-'.Str::random(8)); } public function checked($key) { $this->active = $key; return $this; } public function click() { $this->click = true; return $this; } public function add($items) { if ($items instanceof Arrayable) { $items = $items->toArray(); } $this->items = (array) $items; return $this; } public function map(\Closure $closure) { $this->builder = $closure; return $this; } public function render() { if ($this->click) { Admin::script( <<id} li').on('click', function () { $('#{$this->id} li').removeClass('active'); $(this).addClass('active'); }); JS ); } $html = ''; foreach ($this->items as $k => $item) { if ($builder = $this->builder) { $item = $builder($item, $k); } $active = $this->active === $k ? 'active' : ''; $item = mb_strpos($item, '') ? $item : "$item"; $html .= "
  • $item
  • "; } return ""; } }