Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Menu Laravel Package

spatie/menu

Fluent, extensible menu builder for Laravel. Compose navigation with a clean API, render as HTML, and customize output via presenters and macros. Supports active state handling, links, submenus, and easy integration with Blade and your app’s routing.

View on GitHub
Deep Wiki
Context7

title: Item Attributes weight: 1

The Menu and Link classes use the HtmlAttributes trait, which enables you to add attributes to their main elements (respectively the ul and a tags).

Adding classes to a menu

The trait provides two methods to set attributes: setAttribute and addClass.

Menu::new()
    ->setAttribute('role', 'navigation')
    ->addClass('nav');
<ul role="navigation" class="nav"></ul>

The setAttribute and addClass methods are smart enough to merge class names on render. The latter can also accepts both arrays and strings.

Link::to('#', 'Back to top')
    ->setAttribute('class', 'link')
    ->addClass(['button', 'top']);
<a href="#" class="link button top">Back to top</a>

If you want to add classes or set attributes to all items in a menu, the Menu class provides some convenience methods: addItemClass, setItemAttribute.

Adding an ID to a menu

The trait provides two methods to set attributes: setAttribute and id.

Menu::new()
    ->setAttribute('role', 'navigation')
    ->id('nav');
<ul role="navigation" id="nav"></ul>
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
terminal42/code-quality-tools
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky