Weave 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
Laravel Menu

Laravel Menu Laravel Package

spatie/laravel-menu

Fluent interface for building HTML menus in Laravel. Define menus with convenient URL and action helpers, mark active items from the current request, and render them in your Blade views.

View on GitHub
Deep Wiki
Context7

spatie/laravel-menu provides a fluent interface for building HTML menus in Laravel, wrapping the framework-agnostic spatie/menu package with Laravel-friendly helpers for URL generation and macros. Define a menu once as a macro, render it in Blade, and let the package handle active state detection from the current request.

  • Fluent, chainable API for links, controller actions, and routes
  • Request-aware active states via setActiveFromRequest()
  • Reusable menu macros for rendering anywhere in Blade views
  • Nested submenus, custom HTML attributes, and separators
  • Framework-agnostic core extended with Laravel URL conveniences
Frequently asked questions about Laravel Menu
How do I install spatie/laravel-menu in a Laravel application?
Install it with Composer using composer require spatie/laravel-menu. The service provider and Menu facade are auto-discovered, so no manual registration is needed in a standard Laravel app. There are no migrations, database tables, queue workers, or external services involved, so installation is effectively complete once Composer finishes. After that you can define your first menu and render it in a Blade view.
Which Laravel versions does spatie/laravel-menu support?
The package has tracked Laravel major releases from 5.6 through 13, with Laravel 13 support landing in version 4.2.2. Compatibility has historically arrived as discrete releases rather than a continuously verified version range, so always check the current composer constraint and changelog before upgrading. Budget a small upgrade task each time you move to a new Laravel major. Pinning the package version in composer.json keeps upgrades predictable.
How do I render a menu in Blade and should I worry about XSS?
The documented rendering path is {!! Menu::main() !!}, which outputs raw HTML because the menu renders anchors and active-state classes. That means any label coming from user input, database content, or translated strings with interpolated user data becomes a potential XSS vector unless it is escaped before being passed to the menu. Make escaping an explicit code-review rule rather than an assumption. Static, developer-authored labels are safe by nature.
Why is setActiveFromRequest() highlighting the wrong menu item?
setActiveFromRequest() compares menu URLs against the current request, so it is a heuristic rather than a routing-aware matcher. Overlapping route prefixes, wildcard routes, and pages that differ only by query string can all produce incorrect highlighting. The fix is usually configuration work: override the active state per item for edge cases instead of treating it as a package defect. Map out your navigation regions first, since this is the most common source of reported menu bugs.
How do I register reusable menus with Menu::macro?
Define a macro such as Menu::macro('main', function () { return Menu::new()->route('home', 'Home')->setActiveFromRequest(); }) and render it later with {!! Menu::main() !!}. A dedicated service provider or an App\Menus namespace is the sane place to keep these definitions so they do not drift into a second, parallel routing table. Registering menus once keeps navigation logic in a single testable composition primitive instead of scattered Blade partials.
Can I generate menu links from route names and controller actions?
Yes. The package adds Laravel-specific helpers on top of spatie/menu, letting you build links with action('HomeController@index', 'Home'), route names, and plain URLs. URL generation is delegated to Laravel's own route(), action(), and url() helpers, so the menu inherits the framework's routing contract rather than duplicating it. This means route model binding and named-route changes flow through automatically.
Are spatie/laravel-menu macros safe with Laravel Octane and long-running workers?
Macros register onto a static registry, so in Octane, queue-driven rendering, or a large feature-test suite a re-registered or leaked macro can contaminate later requests or tests. Register macros once in a service provider rather than inside controllers or Blade views. If you register dynamically, reset the registry during test teardown or worker boot as a matter of policy. Treated as policy, the risk is contained and easy to audit.
How do I test menus built with spatie/laravel-menu?
Menus are plain PHP objects, so you can instantiate a menu in a test and assert against the rendered HTML string, including active classes. Register your macros in a service provider so both tests and production use the identical definitions. Reset or re-register macros in test teardown to avoid cross-test contamination. Asserting on rendered output also catches escaping regressions early.
Can I create submenus or extend spatie/laravel-menu with custom items?
Yes, menus can contain nested items, and the package is explicitly designed to be extended through custom macros and custom menu item classes when the built-in link, action, and route helpers are not enough. Because it is a thin Laravel adapter over spatie/menu, most customisation happens by composing or subclassing the underlying menu item types. Complex dropdown behaviour is usually handled by your own Blade markup around the rendered list. Keep customisations in your app namespace so package upgrades stay painless.
What are the alternatives to spatie/laravel-menu and when should I use it?
The alternative is hand-rolled navigation in Blade partials or a full admin/CRUD package that stores menus in the database. spatie/laravel-menu is the right choice when menus are developer-defined, route-driven, and belong in the view layer, because it replaces ad-hoc navigation logic with one testable primitive. It is deliberately narrow: it generates anchors and active-state classes and nothing else. If you need database-managed menus with a UI, this package is not that tool, and the codebase is small and MIT-licensed, so forking is a viable fallback if maintenance slows.
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.
dbravoan/dbcms-admin-theme-dbcms
dbravoan/dbcms-theme-db-cyber
dbravoan/dbcms-blocks-basic
dbravoan/dbcms-module-content-audit
dbravoan/dbcms-module-ai-assistant
paygate-to/paygate-php
padosoft/askmydocs-connector-base
defstudio/supercharged-carbon
bernskioldmedia/laravel-matomo
bernskioldmedia/laravel-harvest
bernskiold/laravel-data-scrubber
bernskiold/laravel-currency-converter
bernskiold/laravel-campaign-monitor
bernskioldmedia/laravel-autotranslate
siberfx/telegram-bot
roy-sandip/laravel-view-extended
gregsphotography/site-builder-core
roy-sandip/laravel-view
anodyne/blade-fluentui-icons
webx-ui/module-catalog-collections