diff --git a/src/Models/MenuGenerator.php b/src/Models/MenuGenerator.php index cad2d46..f29a190 100755 --- a/src/Models/MenuGenerator.php +++ b/src/Models/MenuGenerator.php @@ -260,6 +260,16 @@ protected function add(array $properties = []): MenuItem return $item; } + /** + * Returns an array of menu items to be used without render. + * + * @return \Illuminate\Support\Collection + */ + public function getItems(): Collection + { + return $this->items; + } + /** * Create new menu with dropdown. * diff --git a/src/Models/MenuManager.php b/src/Models/MenuManager.php index fe9d37a..8108140 100755 --- a/src/Models/MenuManager.php +++ b/src/Models/MenuManager.php @@ -110,16 +110,16 @@ public function register($name, Closure $callback): void } /** - * Render the menu tag by given name. + * Initializes the menu tag by given name without rendering. * - * @param string $name - * @param string $presenter - * @param array $bindings - * @param bool $specialSidebar + * @param string $name + * @param string|null $presenter + * @param array $bindings + * @param bool $specialSidebar * - * @return string|null + * @return MenuGenerator|null */ - public function render(string $name, string $presenter = null, array $bindings = [], bool $specialSidebar = false): ?string + public function make(string $name, string $presenter = null, array $bindings = [], bool $specialSidebar = false): ?MenuGenerator { if ($this->has($name)) { $instance = $this->instance($name); @@ -137,7 +137,29 @@ public function render(string $name, string $presenter = null, array $bindings = $params ? $callback($instance, ...$params) : $callback($instance); }); - return $instance->setBindings($bindings)->render($presenter, $specialSidebar); + return $instance->setBindings($bindings); + } + + return null; + } + + /** + * Render the menu tag by given name. + * + * @param string $name + * @param string|null $presenter + * @param array $bindings + * @param bool $specialSidebar + * + * @return string|null + */ + public function render(string $name, string $presenter = null, array $bindings = [], bool $specialSidebar = false): ?string + { + if ($this->has($name)) { + $instance = $this->make($name, $presenter, $bindings, $specialSidebar); + if ($instance) { + return $instance->render($presenter, $specialSidebar); + } } return null;