Menus

Menus are stream entries that represent a collection of links.

Menu Fields

Below is a list of fields in the menus stream. Fields are accessed as attributes:

$menu->name;

Same goes for decorated instances in Twig:

{{ menu.name }}
Fields
Key Type Description

name

text

The menu name.

slug

slug

The menu API slug.

description

textarea

The menu description.

Menu Interface

This section will go over the \Anomaly\NavigationModule\Menu\Contract\MenuInterface class.

MenuInterface::getLinks()

The getLinks method returns a collection of the related menu links.

Returns: \Anomaly\NavigationModule\Link\LinkCollection
Example
foreach ($menu->getLinks() as $link) {
    echo $link->getUrl();
}
Twig
{% for link in menu.getLinks() %}
    {{ link.getUrl() }}
{% endfor %}
MenuInterface::links()

The links method returns the link relation.

Returns: \Illuminate\Database\Eloquent\Relations\HasMany
Example
foreach ($menu->links()->where('parent_id', 1)->get() as $link) {
    echo $link->getUrl();
}
Twig
{% for link in menu.links().where('parent_id', 1).get() %}
    {{ link.getUrl() }}
{% endfor %}

Menu Repository

This class will go over the \Anomaly\NavigationModule\Menu\Contract\MenuRepositoryInterface

MenuRepositoryInterface::findBySlug()

The findBySlug method returns a menu it's slug.

Returns: \Anomaly\NavigationModule\Menu\Contract\MenuInterface or null
Arguments
Key Required Type Default Description

$slug

true

string

none

The slug of the menu to find.