Skip to content

Commit

Permalink
📝 Add simple menu usage documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Log1x committed Aug 20, 2024
1 parent 396d054 commit db8c4ec
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,38 @@ $panel
)
```

### Using Menus

Getting the assigned menu for a registered location can be done using the `Menu` model. Below we will call the menu assigned to the `primary` location:

```php
use Datlechin\FilamentMenuBuilder\Models\Menu;

$menu = Menu::location('primary');
```

Menu items can be iterated from the `menuItems` relationship:

```php
@foreach ($menu->menuItems as $item)
<a href="{{ $item->url }}">{{ $item->title }}</a>
@endforeach
```

When a menu item is a parent, a collection of the child menu items will be available on the `children` property:

```php
@foreach ($menu->menuItems as $item)
<a href="{{ $item->url }}">{{ $item->title }}</a>

@if ($item->children)
@foreach ($item->children as $child)
<a href="{{ $child->url }}">{{ $child->title }}</a>
@endforeach
@endif
@endforeach
```

## Changelog

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.
Expand Down

0 comments on commit db8c4ec

Please sign in to comment.