setTemplate('breadcrumbs'); } public function data() { $data = parent::data(); if ($this->activateLast) { $data['crumbs'][array_key_last($data['crumbs'])]['active'] = true; } return $data; } /** * Add Crumb * @param string $title * @param string $link * @param array $opts * @return bool */ public function add(string $title, string $link = '', array $opts = []) { if ($title === '') { return false; } $crumb = $this->defaults($opts, [ $this->titleKey => $title, 'link' => $link, 'link_title' => $title, 'active' => false, ]); $key = $opts['key'] ?? null; if ($key) { $this->crumbs[$key] = $crumb; } else { $this->crumbs[] = $crumb; } return true; } /** * Add list of crumbs * @param array $crumbs * @param Closure|null $transform * @return static */ public function fill(array $crumbs, ?Closure $transform = null) { if ($transform) { foreach ($crumbs as $key => $crumb) { $crumbs[$key] = $transform($crumb, $key); } } foreach ($crumbs as $crumb) { if (is_array($crumb)) { $this->add($crumb['title'] ?? '', $crumb['link'] ?? '', $crumb); } } return $this; } /** * Update crumb data * @param array $data * @param mixed|null $key crumb key or null (last) * @return static */ public function update(array $data, $key = null) { $key = $key ?? array_key_last($this->crumbs); if (array_key_exists($key, $this->crumbs)) { $this->crumbs[$key] = array_merge($this->crumbs[$key], $data); } return $this; } /** * Reset crumbs list * @return static */ public function reset() { $this->crumbs = []; return $this; } /** * Get crumbs list * @return array */ public function get() { return $this->crumbs; } }