Skip to content

zharinovAlex/menu

 
 

Repository files navigation

Html Menu Generator

Latest Version on Packagist Software License Build Status SensioLabsInsight Quality Score Total Downloads

The spatie/menu package provides a fluent interface to build menus of any size in your php application.

Documentation is available at https://docs.spatie.be/menu.

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.

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');
<ul>
    <li><a href="/">Home</a></li>
    <li><a href="/about">About</a></li>
    <li><a href="/contact">Contact</a></li>
</ul>

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.

Menu::new()
    ->addClass('navigation')
    ->add(Link::to('/', 'Home')->addClass('home-link'))
    ->add(Link::to('/about', 'About'))
    ->add(Link::to('/contact', 'Contact')->addParentClass('float-right'));
<ul class="navigation">
    <li><a href="/" class="home-link">Home</a></li>
    <li><a href="/about">About</a></li>
    <li class="float-right"><a href="/contact">Contact</a></li>
</ul>

Not Afraid of Depths

The menu supports submenus, which in turn can be nested infinitely.

Menu::new()
    ->add(Link::to('/', 'Home'))
    ->add(Menu::new()
        ->addClass('submenu')
        ->add(Link::to('/about', 'About'))
        ->add(Link::to('/contact', 'Contact'))
    );
<ul>
    <li><a href="/">Home</a></li>
    <li>
        <ul class="submenu">
            <li><a href="/about">About</a></li>
            <li><a href="/contact">Contact</a></li>
        </ul>
    </li>
</ul>

Spatie is a webdesign agency based in Antwerp, Belgium. You'll find an overview of all our open source projects on our website.

Install

You can install the package via composer:

$ composer require spatie/menu

Usage

Documentation is available at https://docs.spatie.be/menu.

Changelog

Please see CHANGELOG for more information what has changed recently.

Testing

$ phpunit

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

About Spatie

Spatie is a webdesign agency based in Antwerp, Belgium. You'll find an overview of all our open source projects on our website.

License

The MIT License (MIT). Please see License File for more information.