Skip to content

Commit

Permalink
Add MenuCollection::fill() method so we can fill the collection from …
Browse files Browse the repository at this point in the history
…where we want
  • Loading branch information
jyrkidn committed Sep 20, 2023
1 parent c878b6e commit 9dd9ff1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
8 changes: 1 addition & 7 deletions src/Http/Middleware/MenuMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,7 @@ class MenuMiddleware
{
public function handle(Request $request, Closure $next): Response
{
if (MenuCollection::isNotEmpty()) {
return $next($request);
}

Menu::get()->each(function (Menu $menu) {
MenuCollection::addMenu($menu);
});
MenuCollection::fill();

return $next($request);
}
Expand Down
13 changes: 13 additions & 0 deletions src/MenuCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,19 @@

class MenuCollection extends Collection
{
public function fill()
{
if ($this->isNotEmpty()) {
return $this;
}

Menu::get()->each(function (Menu $menu) {
$this->addMenu($menu);
});

return $this;
}

public function addMenu(Menu $menu)
{
$navigation = $this->newEmptyNavigation();
Expand Down
2 changes: 1 addition & 1 deletion src/View/Components/MenuRender.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public function __construct(
public string $identifier,
public string $view = 'filament-menu::components.render.root',
) {
//
MenuCollection::fill();
}

public function render(): View
Expand Down

0 comments on commit 9dd9ff1

Please sign in to comment.