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: Conditionally Adding Items weight: 3

v1.1+

The add method has an equivalent method with an if suffix, which takes a condition as it's first argument. The items will only be added to the menu if the condition resolves to true (non-strict).

Menu::new()
    ->add(Link::to('/', 'Home'))
    ->addIf(!$loggedIn, Link::to('/login', 'Login'))
    ->addIf(!$loggedIn, Link::to('/register', 'Register'))
    ->addIf($loggedIn, Link::to('/logout', 'Logout'))
<!-- $loggedIn = false -->
<ul>
    <li><a href="/">Home</a></li>
    <li><a href="/login">Login</a></li>
    <li><a href="/register">Register</a></li>
</ul>
<!-- $loggedIn = true -->
<ul>
    <li><a href="/">Home</a></li>
    <li><a href="/logout">Logout</a></li>
</ul>

This also applies to the convenience methods:

Menu::new()
    ->link('/', 'Home')
    ->htmlIf(count($notifications), '<i data-notifications data-icon="bell"></i>');
<!-- $notifications = [] -->
<ul>
    <li><a href="/">Home</a></li>
</ul>
<!-- $notifications = ['new-message'] -->
<ul>
    <li><a href="/">Home</a></li>
    <li><i data-notifications data-icon="bell"></i></li>
</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.
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui