*/ protected Collection $startItems; /** * @var Collection */ protected Collection $midItems; /** * @var Collection */ protected Collection $endItems; /** * @var Collection */ protected Collection $filterItems; /** * @template TModel of Model * @param TableComponent $table */ public function __construct( private TableComponent $table ) { $this->startItems = collect(); $this->midItems = collect(); $this->endItems = collect(); $this->filterItems = collect(); } private function processItem(ToolbarItem $item): void { $item->setToolbar($this); if ($item instanceof FilterItem) { $this->filterItems->push($item); } else if ($item instanceof PageSizeItem) { $this->pageSizeItem = $item; } else if ($item instanceof SearchItem) { $this->searchItem = $item; } } /** * @param Collection $list */ private function prependItem(Collection $list, ToolbarItem $item): static { $this->processItem($item); $list->prepend($item); return $this; } /** * @param Collection $list */ private function appendItem(Collection $list, ToolbarItem $item): static { $this->processItem($item); $list->push($item); return $this; } public function prependStart(ToolbarItem $item): static { return $this->prependItem($this->startItems, $item); } public function appendStart(ToolbarItem $item): static { return $this->appendItem($this->startItems, $item); } public function prependMid(ToolbarItem $item): static { return $this->prependItem($this->midItems, $item); } public function appendMid(ToolbarItem $item): static { return $this->appendItem($this->midItems, $item); } public function prependEnd(ToolbarItem $item): static { return $this->prependItem($this->endItems, $item); } public function appendEnd(ToolbarItem $item): static { return $this->appendItem($this->endItems, $item); } /** * @return TableComponent */ public function getTable(): TableComponent { return $this->table; } public function getSearch(): ?SearchItem { return $this->searchItem; } public function getPageSize(): ?PageSizeItem { return $this->pageSizeItem; } /** * @return Collection */ public function getFilters(): Collection { return $this->filterItems; } public function render(): View { return view('laralight-tables::toolbar', [ 'startItems' => $this->startItems, 'midItems' => $this->midItems, 'endItems' => $this->endItems, ]); } }