PHPackages                             sagsoz06/laravel-menus - 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. sagsoz06/laravel-menus

ActiveLibrary

sagsoz06/laravel-menus
======================

Laravel Menu management

0.3.2(8y ago)01311MITPHPPHP &gt;=5.5.9

Since Mar 31Pushed 8y ago1 watchersCompare

[ Source](https://github.com/sagsoz06/laravel-menus)[ Packagist](https://packagist.org/packages/sagsoz06/laravel-menus)[ RSS](/packages/sagsoz06-laravel-menus/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (9)Versions (9)Used By (1)

[![Latest Version on Packagist](https://camo.githubusercontent.com/1c6b82f2ae694a73f451db65345e66c2e256712b821cdfe71c6f757eab294683/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6e7769646172742f6c61726176656c2d6d656e75732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/nwidart/laravel-menus)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/a971c8c67c07916f7c3abf60a848727325a708c17db96441e50bcf3d663837cb/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6e5769646172742f6c61726176656c2d6d656e75732f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/nWidart/laravel-menus)[![Scrutinizer Coverage](https://camo.githubusercontent.com/e1ba6514a3d222b525c0e99a68e641b31ae2b4d1d9fa8b077ff1420aa2ba5436/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f6e5769646172742f6c61726176656c2d6d656e75732e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/nWidart/laravel-menus/?branch=master)[![SensioLabsInsight](https://camo.githubusercontent.com/23306e44cc0be0b13b7cc52f41d7adda64498816f788147274af0efc6ebee3f1/68747470733a2f2f696d672e736869656c64732e696f2f73656e73696f6c6162732f692f36623138373431302d653538362d343635662d613133372d3264316662663761633732342e7376673f7374796c653d666c61742d737175617265)](https://insight.sensiolabs.com/projects/6b187410-e586-465f-a137-2d1fbf7ac724)[![Quality Score](https://camo.githubusercontent.com/a60b901f778183fec48720dab9b2c8f92a0e4dc782db4f7e356e0d7313540b25/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f6e5769646172742f6c61726176656c2d6d656e75732e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/nWidart/laravel-menus)[![Total Downloads](https://camo.githubusercontent.com/c40e9efb2b7d6f54c9b1dc5dd03cabcdf146e58461629977ce87f6c9b9829718/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6e7769646172742f6c61726176656c2d6d656e75732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/nwidart/laravel-menus)

Laravel Menus
=============

[](#laravel-menus)

`nwidart/laravel-menus` is a laravel package which created to manage menus. It has a feature called presenters which enables easy styling and custom structure of menu rendering.

This package is a re-published, re-organised and maintained version of [pingpong/menus](https://github.com/pingpong-labs/menus), which isn't maintained anymore. This package is used in [AsgardCMS](https://asgardcms.com/).

With one big added bonus that the original package didn't have: **tests**.

- [Installation](#installation)
- [Creating A Menu](#creating-a-menu)
    - [Menu Item](#menu-item)
    - [Menu Dropdown](#menu-dropdown)
    - [Menu Dropdown Milti Level](#menu-dropdown-multi-level)
    - [Menu Divider](#menu-divider)
    - [Dropdown Header](#dropdown-header)
    - [Ordering Menu Item](#ordering-menu-item)
    - [Make Lots of Menu](#make-lots-of-menu)
- [Menu Presenter](#menu-presenter)
    - [The Available Presenter](#available-presenter)
    - [Make A Custom Presenter](#make-a-custom-presenter)
    - [Register A New Menu Style](#register-a-menu-style)
- [View Presenter](#view-presenter)
    - [The Available View Presenter](#available-view-presenter)
- [Rendering Menu](#rendering-menu)
- [Menu Inheritance](#menu-inheritance)
    - [Menu Instance](#menu-instance)
    - [Finding Menu Item](#finding-menu-item)
    - [Modifying Menu](#modifying-menu)

Installation
------------

[](#installation)

You can install the through composer command line.

```
composer require nwidart/laravel-menus

```

After the package installed, add a new service provider to the `providers` array in `config/app.php` file.

```
'providers' => [
	Nwidart\Menus\MenusServiceProvider::class,
],
```

Add new alias for `Menu` facade to the `aliases` array at the same file.

```
'aliases' => array(
	'Menu' => Nwidart\Menus\Facades\Menu::class,
)
```

Then, publish package's assets by running:

```
php artisan vendor:publish --provider="Nwidart\Menus\MenusServiceProvider"

```

Creating A Menu
---------------

[](#creating-a-menu)

You can define your menus in `app/Support/menus.php` file. That file will loaded automatically by this package.

To create a menu, simply call the `create` method from `Menu` facade. The first parameter is the menu name and the second parameter is callback for defining menu items.

```
Menu::create('navbar', function($menu) {
    // define your menu items here
});
```

### Menu Item

[](#menu-item)

As explained before, we can defining menu item in the callback by accessing `$menu` variable, which the variable is instance of `Nwidart\Menus\MenuBuilder` class.

To defining a plain URL, you can use `->url()` method.

```
Menu::create('navbar', function($menu) {
    // URL, Title, Attributes
    $menu->url('home', 'Home', ['target' => 'blank']);
});
```

If you have named route, you define the menu item by calling `->route()` method.

```
Menu::create('navbar', function($menu) {
	$menu->route(
        'users.show', // route name
        'View Profile', // title
        ['id' => 1], // route parameters
        ['target' => 'blank'] // attributes
    );
});
```

You can also defining the menu item via array by calling `->add()` method.

```
Menu::create('navbar', function($menu) {
    $menu->add([
        'url' => 'about',
        'title' => 'About',
        'attributes' => [
            'target' => '_blank'
        ]
    ]);

    $menu->add([
        'route' => ['profile', ['user' => 'nwidart']],
        'title' => 'Visit My Profile',
        'attributes' => [
            'target' => '_blank'
        ]
    ]);
});
```

### Menu Dropdown

[](#menu-dropdown)

To create a dropdown menu, you can call to `->dropdown()` method and passing the first parameter by title of dropdown and the second parameter by closure callback that retrieve `$sub` variable. The `$sub` variable is the the instance of `Nwidart\Menus\MenuItem` class.

```
Menu::create('navbar', function($menu) {
    $menu->url('/', 'Home');
    $menu->dropdown('Settings', function ($sub) {
        $sub->url('settings/account', 'Account');
        $sub->url('settings/password', 'Password');
        $sub->url('settings/design', 'Design');
    });
});

```

### Menu Dropdown Multi Level

[](#menu-dropdown-multi-level)

You can also create a dropdown inside dropdown by using `->dropdown()` method. This will allow to to create a multilevel menu items.

```
Menu::create('navbar', function($menu) {
    $menu->url('/', 'Home');
    $menu->dropdown('Account', function ($sub) {
        $sub->url('profile', 'Visit My Profile');
        $sub->dropdown('Settings', function ($sub) {
            $sub->url('settings/account', 'Account');
            $sub->url('settings/password', 'Password');
            $sub->url('settings/design', 'Design');
        });
        $sub->url('logout', 'Logout');
    });
});

```

### Menu Divider

[](#menu-divider)

You may also define a divider for each menu item. You can divide between menu item by using `->divider()` method.

```
Menu::create('navbar', function($menu) {
    $menu->url('/', 'Home');
    $menu->divider();
    $menu->url('profile', 'Profile')
});
```

### Dropdown Header

[](#dropdown-header)

You may also add a dropdown header for the specified menu item by using `->header()` method.

```
Menu::create('navbar', function($menu) {
    $menu->url('/', 'Home')
    $menu->dropdown('Settings', function ($sub) {
        $sub->header('ACCOUNT');
        $sub->url('/settings/design', 'Design');
        $sub->divider();
        $sub->url('logout', 'Logout');
    });
});
```

### Ordering Menu Item

[](#ordering-menu-item)

You may order the menu by specify `order` parameter.

```
Menu::create('navbar', function($menu) {
    $menu->url('/', 'Home', 1);
    $menu->route('/', 'About', ['user' => '1'], 2);
    $menu->dropdown('Settings', function ($sub) {
        $sub->header('ACCOUNT');
        $sub->url('/settings/design', 'Design');
        $sub->divider();
        $sub->url('logout', 'Logout');
    }, 3);
});
```

You may also set the order value by calling `->order` method.

```
Menu::create('navbar', function($menu) {
    $menu->url('/', 'Home', ['icon' => 'fa fa-dashboard'])->order(1);
    $menu->route('/', 'About', ['user' => '1'], ['icon' => 'fa fa-user'])->order(2);
    $menu->dropdown('Settings', function ($sub) {
        $sub->header('ACCOUNT');
        $sub->url('/settings/design', 'Design');
        $sub->divider();
        $sub->url('logout', 'Logout');
    })->order(3);
});
```

By default ordering feature is disabled. You can enable the `ordering` feature in your config file. Just update value of `ordering` config to `true` and now your menu will ordered by `order` key.

```
return [
	'ordering' => true
];
```

You may also enable or disable menu ordering for each menu via `->enableOrdering` and `->disableOrdering` method.

```
Menu::create('navbar', function($menu) {
    // disable menu ordering
    $menu->enableOrdering();

    // disable menu ordering
    $menu->disableOrdering();
});
```

### Make many of menus

[](#make-many-of-menus)

You can also create a set of menus with different name and menu items.

```
Menu::create('menu1', function($menu) {
	$menu->route('home', 'Home');
    $menu->url('profile', 'Profile');
});

Menu::create('menu2', function($menu) {
    $menu->route('home', 'Home');
    $menu->url('profile', 'Profile');
});
```

Menu Presenter
--------------

[](#menu-presenter)

This package includes some presenter classes that are used for converting menus to html. By default the generated menu style is `bootstrap navbar`. But, there are also several different menu styles.

You can apply the menu style via `->style()` method.

```
Menu::create('navbar', function($menu) {
    $menu->style('nav-pills');
});
```

Or you can set which presenter to present the menu style via `->setPresenter()` method.

```
Menu::create('navbar', function($menu) {
    $menu->setPresenter(\Nwidart\Menus\Presenters\Bootstrap\NavTabPresenter::class);
});
```

You can also set which style of presenter when you rendering a menu.

```
Menu::render('navbar', 'navbar-right');

Menu::render('navbar', \Nwidart\Menus\Presenters\Bootstrap\NavPillsPresenter::class);
```

### The List of Available Menu Presenter Class

[](#the-list-of-available-menu-presenter-class)

NamePresenter Class`navbar``Nwidart\Menus\Presenters\Bootstrap\NavbarPresenter``navbar-right``Nwidart\Menus\Presenters\Bootstrap\NavbarRightPresenter``nav-pills``Nwidart\Menus\Presenters\Bootstrap\NavPillsPresenter``nav-tab``Nwidart\Menus\Presenters\Bootstrap\NavTabPresenter``sidebar``Nwidart\Menus\Presenters\Bootstrap\SidebarMenuPresenter``navmenu``Nwidart\Menus\Presenters\Bootstrap\NavMenuPresenter`### Make A custom Presenter

[](#make-a-custom-presenter)

You can create your own presenter classes. Make sure your presenter extends the `Nwidart\Menus\Presenters\Presenter` and `implements` the 'Nwidart\\Menus\\Presenters\\PresenterInterface' interface.

For example, this is `zurb-top-bar` presenter.

```
use Nwidart\Menus\Presenters\Presenter;

class ZurbTopBarPresenter extends Presenter
{
	/**
	 * {@inheritdoc }
	 */
	public function getOpenTagWrapper()
	{
		return  PHP_EOL . '' . PHP_EOL;
	}

	/**
	 * {@inheritdoc }
	 */
	public function getCloseTagWrapper()
	{
		return  PHP_EOL . '' . PHP_EOL;
	}

	/**
	 * {@inheritdoc }
	 */
	public function getMenuWithoutDropdownWrapper($item)
	{
		return ''.$item->getIcon().' '.$item->title.'';
	}

	/**
	 * {@inheritdoc }
	 */
	public function getActiveState($item)
	{
		return \Request::is($item->getRequest()) ? ' class="active"' : null;
	}

	/**
	 * {@inheritdoc }
	 */
	public function getDividerWrapper()
	{
		return '';
	}

	/**
	 * {@inheritdoc }
	 */
	public function getMenuWithDropDownWrapper($item)
	{
		return '

		         '.$item->getIcon().' '.$item->title.'

		          '.$this->getChildMenuItems($item).'

		      ' . PHP_EOL;
		;
	}
}
```

To use this custom presenter, you can use the `setPresenter` method.

```
Menu::create('zurb-top-bar', function($menu) {
    $menu->setPresenter('ZurbTopBarPresenter');
});
```

### Register A New Menu Style

[](#register-a-new-menu-style)

Menu style is like an alias to a presenter. You can register your style from your costum presenter in the configuration file in `config/menus.php`.

```
return [
	'navbar'		=>	'Nwidart\Menus\Presenters\Bootstrap\NavbarPresenter',
	'navbar-right'	=>	'Nwidart\Menus\Presenters\Bootstrap\NavbarRightPresenter',
	'nav-pills'		=>	'Nwidart\Menus\Presenters\Bootstrap\NavPillsPresenter',
	'nav-tab'		=>	'Nwidart\Menus\Presenters\Bootstrap\NavTabPresenter',

	'zurb-top-bar'	=>	'ZurbTopBarPresenter',
];
```

Now, you can use a style like this.

```
Menu::create('zurb-top-bar', function($menu) {
    $menu->style('zurb-top-bar');
});
```

View Presenter
--------------

[](#view-presenter)

If you don't like to use presenter classes, you use view presenters instead. We can set which view to present the menus by calling `->setView()` method.

```
Menu::create('navbar', function($menu) {
    $menu->setView('menus::default');
});

```

### The List of Available View Presenter

[](#the-list-of-available-view-presenter)

View NameMenu Style`menus::default`Bootstrap Navbar (default)`menus::navbar-left`Bootstrap Navbar Left`menus::navbar-right`Bootstrap Navbar Right`menus::nav-tabs`Bootstrap Nav Tabs`menus::nav-tabs-justified`Bootstrap Nav Tabs Justified`menus::nav-pills`Bootstrap Nav Pills`menus::nav-pills-stacked`Bootstrap Nav Pills Stacked`menus::nav-pills-justified`Bootstrap Nav Pills Justified`menus::menu`Plain Menu

Rendering Menu
--------------

[](#rendering-menu)

To render the menu you can use `render` or `get` method.

```
Menu::render('navbar');

Menu::get('navbar');
```

You can also set which style to present the menu in the second parameter.

```
Menu::render('navbar', 'navbar-right');
```

Or you may also set which view to present the menu.

```
Menu::render('navbar', 'menus::nav-tabs');
```

The Menu Instance
-----------------

[](#the-menu-instance)

Sometimes, maybe we need to add a new additional menu from controller or other place. To get an instance of an existing menu, you can use the `instance` method.

```
$menu = Menu::instance('zurb-top-bar');

// You can also make additions to the menu again

$menu->add(['title' => 'Settings', 'route' => 'settings']);

$menu->url('profile', 'Profile');

$menu->route('settings', 'Settings');
```

Finding Menu Item
-----------------

[](#finding-menu-item)

To find menu item, you can use `findBy` method from `Nwidart\Menus\MenuBuilder` class.

```
$menu = Menu::instance('sidebar');

$menu->url('profile', 'Profile');

$menuItem = $menu->findBy('title', 'Profile');

// add child menu
$menuItem->url('foo', 'Foo');
```

You may also use `whereTitle` helper method to find a specific menu item. Also, you can add other child menu item in the callback that located in the second argument in `whereTitle` method.

```
$menu = Menu::instance('sidebar');

$menu->url('profile', 'Profile');

$menu->whereTitle('Profile', function ($sub)
{
	$sub->url('foo', 'Foo');
});

// add childs menu
```

Modifying Menu
--------------

[](#modifying-menu)

After we create a menu, maybe we need to add other additional menus. You may modifying menu via `->modify` method.

```
Menu::modify('navbar', function($menu)
{
	$menu->add([
		'title' => 'Foo',
		'url' => 'bar',
	]);
});

```

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 66.7% 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

Every ~23 days

Recently: every ~41 days

Total

8

Last Release

3166d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/97d293b3dd3a4e7655fb8b6c0245cb27adf9857bf3400df1730bbcf51d6be27a?d=identicon)[sagsoz06](/maintainers/sagsoz06)

---

Top Contributors

[![visualturk](https://avatars.githubusercontent.com/u/17029406?v=4)](https://github.com/visualturk "visualturk (6 commits)")[![aniliso](https://avatars.githubusercontent.com/u/26839479?v=4)](https://github.com/aniliso "aniliso (3 commits)")

---

Tags

laravelbootstrapnavigationmenusnav

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/sagsoz06-laravel-menus/health.svg)

```
[![Health](https://phpackages.com/badges/sagsoz06-laravel-menus/health.svg)](https://phpackages.com/packages/sagsoz06-laravel-menus)
```

###  Alternatives

[nwidart/laravel-menus

Laravel Menu management

168180.3k10](/packages/nwidart-laravel-menus)[pingpong/menus

Laravel Menus

70194.4k13](/packages/pingpong-menus)[rinvex/laravel-menus

Rinvex Menus is a simple menu builder package for Laravel, that supports hierarchical structure, ordering, and styling with full flexibility using presenters for easy styling and custom structure of menu rendering.

294.0k20](/packages/rinvex-laravel-menus)

PHPackages © 2026

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