--- title: Introduction weight: 1 --- The `spatie/menu` package provides a fluent interface to build menus of any size in your php application. If you're building your app with Laravel, the `spatie/laravel-menu` provides some extra treats. ## Human Readable, Fluent Interface All classes provide a human readable, fluent interface (no array configuration). Additionally, you can opt for a more verbose and flexible syntax, or for convenience methods that cover most use cases. ```php Menu::new() ->add(Link::to('/', 'Home')) ->add(Link::to('/about', 'About')) ->add(Link::to('/contact', 'Contact')) ->render(); // Or just... Menu::new() ->link('/', 'Home') ->link('/about', 'About') ->link('/contact', 'Contact'); ``` ```html ``` ## Strong Control Over the Html Output You can programatically add html classes and attributes to any item in the menu, or to the menu itself. ```php Menu::new() ->addClass('navigation') ->add(Link::to('/', 'Home')->addClass('home-link')) ->add(Link::to('/about', 'About')) ->add(Link::to('/contact', 'Contact')->addParentClass('float-right')) ->wrap('div', ['class' => 'wrapper']) ``` ```html
id('navigation') ->add(Link::to('/', 'Home')->id('home-link')) ->add(Link::to('/about', 'About')) ->add(Link::to('/contact', 'Contact')) ``` ```html ``` ## Not Afraid of Depths The menu supports submenus, which in turn can be nested infinitely. ```php Menu::new() ->add(Link::to('/', 'Home')) ->submenu('More', Menu::new() ->addClass('submenu') ->link('/about', 'About') ->link('/contact', 'Contact') ); ``` ```html ``` ## Some Extra Treats for Laravel Apps The Laravel version of the menu package adds some extras like convenience methods for generating URLs and macros. ```php Menu::macro('main', function () { return Menu::new() ->action('HomeController@index', 'Home') ->action('AboutController@index', 'About') ->action('ContactController@index', 'Contact') ->setActiveFromRequest(); }); ``` ```html ``` ## We have badges!
spatie/menu Latest Version on Packagist Software License Build Status Quality Score Total Downloads
spatie/laravel-menu Latest Version on Packagist Software License Build Status Quality Score Total Downloads