The Menus are lists of links that appear on your application.
Registering menus allow for creating easily customizable menus areas, which can be managed inside Appearance > Menus
administration panel.
All application menus should be defined inside app\Support\menus.php
file. This file is included on application bootstrap by the App\Providers\AppServiceProvider
class.
Registering menus are really simple. All you have to do is to call create
method on Menu
facade.
Menu::create('primary');
Create method accepts options as the second argument.
Menu::create('primary', [
'title' => ['Main menu'],
]);
List of available options:
Option name | Default value | Description |
---|---|---|
title | [] |
Menu title displayed in the admin |
Calling get
method will return previously registered menu instance.
Menu::get('primary');
You can check if menu contains any items with isActive
method.
@if(Menu::get('primary')->isActive())
// ...menu have items
@endif
Grab all menu items with items
method. This will return a collection of Assely\Adapter\Menu
instances.
<!-- resources/views/index.blade.php -->
<div class="menu--primary">
@include('menu.nav', [
'items' => Menu::get('primary')->items()
])
</div>
Now, you only need to loop through items in a @foreach statement.
<!-- resources/views/menu/nav.blade.php -->
<ul>
@foreach($items as $item)
<li>
<a href="{{ $item->link }}">{{ $item->title }}</a>
<!--
If menu item have children items,
recursively include this view.
-->
@if($item->hasChildren())
@include('menu.nav', [
'items' => $item->children()
])
@endif
</li>
@endforeach
</ul>