PHPackages                             hoangphison/menu - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. hoangphison/menu

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

hoangphison/menu
================

Html menu generator

1.0.0(8y ago)0501MITPHPPHP &gt;=5.6

Since Mar 7Pushed 8y agoCompare

[ Source](https://github.com/hoangphison/menu)[ Packagist](https://packagist.org/packages/hoangphison/menu)[ Docs](https://github.com/hoangphison/menu)[ RSS](/packages/hoangphison-menu/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependencies (2)Versions (5)Used By (1)

Html Menu Generator
===================

[](#html-menu-generator)

[![Build Status](https://camo.githubusercontent.com/d69b23196a52cf6e7790b2c5a87e6df0ed6098874445d0220b5281e7898a9414/68747470733a2f2f7472617669732d63692e6f72672f686f616e67706869736f6e2f6d656e752e7376673f6272616e63683d66656174757265253246706870352e362d636f6d7061746962696c697479)](https://travis-ci.org/hoangphison/menu)[![StyleCI](https://camo.githubusercontent.com/a977a3adc782d5cc5482a063db3ff2f9b53fd1fd1bb188025e6aa868801cfc01/68747470733a2f2f7374796c6563692e696f2f7265706f732f3131313930303232332f736869656c643f6272616e63683d6d6173746572)](https://styleci.io/repos/111900223)

The `hoangphison/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 [`hoangphison/laravel-menu`](https://github.com/hoangphison/laravel-menu) provides some extra treats.

Documentation is available at .

Upgrading from version 1? There's a [guide](https://github.com/spatie/menu#upgrading-to-20) for that!

Human Readable, Fluent Interface
--------------------------------

[](#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::newMenu()
    ->add(Link::to('/', 'Home'))
    ->add(Link::to('/about', 'About'))
    ->add(Link::to('/contact', 'Contact'))
    ->add(Html::empty())
    ->render();

// Or just...
Menu::newMenu()
    ->link('/', 'Home')
    ->link('/about', 'About')
    ->link('/contact', 'Contact')
    ->empty()
```

```

    Home
    About
    Contact

```

Or a More Programmatic Approach
-------------------------------

[](#or-a-more-programmatic-approach)

Menus can also be created through a reduce-like callable.

```
$pages = [
    '/' => 'Home',
    '/about' => 'About',
    '/contact' => 'Contact',
];

Menu::build($pages, function ($menu, $label, $url) {
    $menu->add($url, $label);
})->render();
```

```

    Home
    About
    Contact

```

Strong Control Over the Html Output
-----------------------------------

[](#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::newMenu()
    ->addClass('navigation')
    ->add(Link::to('/', 'Home')->addClass('home-link'))
    ->add(Link::to('/about', 'About'))
    ->add(Link::to('/contact', 'Contact')->addParentClass('float-right'))
    ->wrap('div.wrapper')
```

```

        Home
        About
        Contact

link('/', 'Home')
    ->submenu('More', Menu::newMenu()
        ->addClass('submenu')
        ->link('/about', 'About'))
        ->link('/contact', 'Contact'))
    );
```

```

    Home

        More

            About
            Contact

```

Some Extra Treats for Laravel Apps
----------------------------------

[](#some-extra-treats-for-laravel-apps)

The Laravel version of the menu package adds some extras like convenience methods for generating URLs and macros.

```
Menu::macro('main', function () {
    return Menu::new()
        ->action('HomeController@index', 'Home')
        ->action('AboutController@index', 'About')
        ->action('ContactController@index', 'Contact')
        ->setActiveFromRequest();
});
```

```

    {{ Menu::main() }}

```

Spatie is a webdesign agency based in Antwerp, Belgium. You'll find an overview of all our open source projects [on our website](https://spatie.be/opensource).

Install
-------

[](#install)

You can install the package via composer:

```
$ composer require hoangphison/menu
```

Usage
-----

[](#usage)

Documentation is available at .

Upgrading to 2.0
----------------

[](#upgrading-to-20)

Upgrading to 2.0 should be pretty painless for most use cases.

### If you're just building menus...

[](#if-youre-just-building-menus)

- The `void` and `voidIf` have been removed. These can be replaced by `html` and `htmlIf`, with empty strings as their first arguments
- The `prefixLinks` and `prefixUrls` methods have been removed because they were too unpredictable in some case. There currently isn't an alternative for these, besides writing your own logic and applying it with `applyToAll`.

### If you're using custom `Item` implementations...

[](#if-youre-using-custom-item-implementations)

- The `HtmlAttributes` and `ParentAttributes` traits have been renamed to `HasHtmlAttributes` and `HasParentAttributes`.
- The `HasUrl` interface and trait has been removed. Url-related methods now also are part of the `Activatable` interface and trait.

### New features...

[](#new-features)

- Added the static `Menu::build` and non-static `Menu::fill` methods to create menu's from arrays.
- The `setActive` method on `Activatable` now also accepts a non-strict boolean or callable parameter to set `$active` to true or false.
- `Menu::html` and `Menu::htmlIf` now accept a `$parentAttributes` array as their second arguments.

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

Testing
-------

[](#testing)

```
$ phpunit
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security
--------

[](#security)

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

Postcardware
------------

[](#postcardware)

You're free to use this package, but if it makes it to your production environment we highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using.

Our address is: Spatie, Samberstraat 69D, 2060 Antwerp, Belgium.

We publish all received postcards [on our company website](https://spatie.be/en/opensource/postcards).

Credits
-------

[](#credits)

- [Sebastian De Deyne](https://github.com/sebastiandedeyne)
- [All Contributors](../../contributors)

Support us
----------

[](#support-us)

Spatie is a webdesign agency based in Antwerp, Belgium. You'll find an overview of all our open source projects [on our website](https://spatie.be/opensource).

Does your business depend on our contributions? Reach out and support us on [Patreon](https://www.patreon.com/spatie). All pledges will be dedicated to allocating workforce on maintenance and new awesome stuff.

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 77.1% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

3090d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/516402738c16a9d7707d638d399b4b2c40cfc27776e8d5e25eea26ee58265b9f?d=identicon)[sonhp](/maintainers/sonhp)

---

Top Contributors

[![sebastiandedeyne](https://avatars.githubusercontent.com/u/1561079?v=4)](https://github.com/sebastiandedeyne "sebastiandedeyne (175 commits)")[![freekmurze](https://avatars.githubusercontent.com/u/483853?v=4)](https://github.com/freekmurze "freekmurze (26 commits)")[![ccsliinc](https://avatars.githubusercontent.com/u/5481458?v=4)](https://github.com/ccsliinc "ccsliinc (8 commits)")[![rojtjo](https://avatars.githubusercontent.com/u/1123887?v=4)](https://github.com/rojtjo "rojtjo (5 commits)")[![markwalet](https://avatars.githubusercontent.com/u/11446771?v=4)](https://github.com/markwalet "markwalet (3 commits)")[![akoepcke](https://avatars.githubusercontent.com/u/5311185?v=4)](https://github.com/akoepcke "akoepcke (2 commits)")[![hoangphison](https://avatars.githubusercontent.com/u/9270621?v=4)](https://github.com/hoangphison "hoangphison (2 commits)")[![daison12006013](https://avatars.githubusercontent.com/u/4581415?v=4)](https://github.com/daison12006013 "daison12006013 (1 commits)")[![matthewtrask](https://avatars.githubusercontent.com/u/4731244?v=4)](https://github.com/matthewtrask "matthewtrask (1 commits)")[![pimlie](https://avatars.githubusercontent.com/u/1067403?v=4)](https://github.com/pimlie "pimlie (1 commits)")[![carusogabriel](https://avatars.githubusercontent.com/u/16328050?v=4)](https://github.com/carusogabriel "carusogabriel (1 commits)")[![Butochnikov](https://avatars.githubusercontent.com/u/4212297?v=4)](https://github.com/Butochnikov "Butochnikov (1 commits)")[![svenluijten](https://avatars.githubusercontent.com/u/11269635?v=4)](https://github.com/svenluijten "svenluijten (1 commits)")

---

Tags

spatiemenunavigationhoangphison

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/hoangphison-menu/health.svg)

```
[![Health](https://phpackages.com/badges/hoangphison-menu/health.svg)](https://phpackages.com/packages/hoangphison-menu)
```

###  Alternatives

[spatie/menu

Html menu generator

7592.9M6](/packages/spatie-menu)[verbb/navigation

Create navigation menus for your site.

90683.7k17](/packages/verbb-navigation)[kartik-v/yii2-widget-sidenav

An enhanced side navigation menu styled for bootstrap (sub repo split from yii2-widgets)

364.0M8](/packages/kartik-v-yii2-widget-sidenav)[caffeinated/menus

Laravel Menus

134159.5k5](/packages/caffeinated-menus)[akaunting/laravel-menu

Menu and sidebar management package for Laravel

38233.8k](/packages/akaunting-laravel-menu)[belugadigital/kirby-navigation

Kirby 5 field for hierarchical menus with drag &amp; drop level indentation.

8713.4k](/packages/belugadigital-kirby-navigation)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
