PHPackages                             delatbabel/nestedmenus - 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. [Database &amp; ORM](/categories/database)
4. /
5. delatbabel/nestedmenus

ActiveLibrary[Database &amp; ORM](/categories/database)

delatbabel/nestedmenus
======================

A Laravel 5 package for nested menus with database storage.

v1.1(10y ago)3481MITPHPPHP &gt;=5.4.0

Since Feb 5Pushed 9y ago2 watchersCompare

[ Source](https://github.com/delatbabel/nestedmenus)[ Packagist](https://packagist.org/packages/delatbabel/nestedmenus)[ RSS](/packages/delatbabel-nestedmenus/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (7)Versions (3)Used By (0)

nestedmenus
===========

[](#nestedmenus)

Database storage of nested menus, including rendering

Based On
--------

[](#based-on)

- [Baum](http://etrepat.com/baum/) for data storage.
- [AdminLTE](https://almsaeedstudio.com/) menu templates.
- [Lavary Menu](https://packagist.org/packages/lavary/laravel-menu) for menu rendering.

Comes with
----------

[](#comes-with)

- Migration for the `menus` table
- Menu Model (that extends Baum/Node so you can use all the handy methods from this excellent nested set implementation)
- Seed for building the menu nodes, one for each type of menu

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

[](#installation)

Add these lines to your composer.json file:

```
    "require": {
        "delatbabel/nestedmenus": "~1.0"
    },

```

Once that is done, run the composer update command:

```
    composer update

```

Alternatively just run this command:

```
    composer require delatbabel/nestedmenus

```

### Register Service Provider

[](#register-service-provider)

After composer update completes, add this line to your config/app.php file in the 'providers' array:

```
    Delatbabel\NestedMenus\NestedMenusServiceProvider::class

```

### Publish the Migrations

[](#publish-the-migrations)

Publish the migrations

```
    php artisan vendor:publish

```

Run the migration

```
    php artisan migrate

```

Ensure the categories `types` are set correctly in the seeder file. You can initialise this to whatever you like.

### Run the Seeders

[](#run-the-seeders)

Run the seed (this will create the base menu structure as defined in the seeder)

```
    php artisan db:seed

```

You may prefer to build your own **MenusTableSeeder** class based on the code in **MenusTableBaseSeeder** to seed your own initial set of menus.

Usage
=====

[](#usage)

This class relies on the behind-the-scenes capabilities of Baum. For details on the use of that see the [README on github](https://github.com/etrepat/baum) or the [Baum web site](http://etrepat.com/baum/)

Creating the Menu Structure
---------------------------

[](#creating-the-menu-structure)

See the MenusTableBaseSeeder for an example of how to build the menu structure in the database. You can in fact just extend this seeder to create your own seeder, just overriding the function getNodes() to provide the menu structure to seed into the database.

Menu editors and the such like are still to be done.

The important parts of the database structure look like this when completed:

```
+----+-----------+------+------+-------+----------------|----------------+-------------------------+-------+
| id | parent_id | lft  | rgt  | depth | slug           | name           | url                     | route |
+----+-----------+------+------+-------+----------------|----------------+-------------------------+-------+
|  1 |      NULL |    1 |   14 |     0 | example-menu   | Example Menu   |                         | NULL  |
|  2 |         1 |    2 |    3 |     1 | example-list   | Example List   | sysadmin/example        | NULL  |
|  3 |         1 |    4 |    5 |     1 | example-create | Example Create | sysadmin/example/create | NULL  |
|  4 |         1 |    6 |   13 |     1 | example-edit   | Example Edit   | sysadmin/example/edit   | NULL  |
|  5 |         4 |    7 |    8 |     2 | example-edit-1 | Example Edit 1 | sysadmin/example/edit/1 | NULL  |
|  6 |         4 |    9 |   10 |     2 | example-edit-2 | Example Edit 2 | sysadmin/example/edit/2 | NULL  |
|  7 |         4 |   11 |   12 |     2 | example-edit-3 | Example Edit 3 | sysadmin/example/edit/3 | NULL  |
+----+-----------+------+------+-------+----------------|----------------+-------------------------+-------+

```

Note that at the moment the renderers available only support a 2 level menu structure. Level 0 is the heading. At level 1 are the various options, and at level 2 are the sub-options for each option.

See the [Baum](http://etrepat.com/baum/) functions for more detail on creating and manipulating this structure.

Loading the Menu Structure
--------------------------

[](#loading-the-menu-structure)

The menu structure can be loaded from the database using any normal Eloquent Model code, for example:

```
    $menu = \Delatbabel\NestedMenus\Models\Menu::where('slug', '=', 'example-menu')->first();
```

Note that you only need to load the top level of the menu in order to be able to render the entire menu.

Rendering the Menu Structure
----------------------------

[](#rendering-the-menu-structure)

See the ShowMenu class under src/Console/Commands for the details on how to do this. It's really simple:

```
    $renderer = new LavarySidebarRenderer();
    $rendered = $renderer->renderToHtml($menu);
```

Rendering to different menu structures requires different renderer classes. I will build more of these over time.

Placing the rendered menu on a view is as simple as this:

```
    return View::make("dashboard.example")
        ->with('sidebar_menu', $sidebar_menu);
```

TODO
====

[](#todo)

Integrate additional menu front end creators. There are a few out there. I have decided to allow for integration of both of these:

-
-

Lavary Menu
-----------

[](#lavary-menu)

Completed a LavarySidebarRenderer class. I had to extend the Lavary menu classes in order to do this, so instead of their main repo use the VCS mentioned in the composer.json in this package. I have submitted a PR to the Lavary repo for this change. See [PR #100](https://github.com/lavary/laravel-menu/pull/100).

Need to have separate renderer classes for the other menu types (header menus, pulldown menus, etc).

Vespakoen Menu
--------------

[](#vespakoen-menu)

TBD

Architecture
============

[](#architecture)

Rationale
---------

[](#rationale)

I want to be able to create [AdminLTE](https://almsaeedstudio.com/) based menus, which look like this:

```

    HEADER

     Link
     Another Link

         Multilevel

            Link in level 2
            Link in level 2

```

I want to be able to create them dynamically rather than embed them in the view files.

I want to be able to store the menu structure in a database table so that it can be modified at run time or without having to change any code.

Imports
-------

[](#imports)

After using [Baum](http://etrepat.com/baum/) successfully for my [Nested Categories](https://github.com/delatbabel/nestedcategories) package, It seemed the obvious choice for heirarchical storage of the menu structure.

The only thing that remained is the creation of the views. I figured that there were a few options:

- Use a Laravel / Blade template to create the menu and import it into a page as a section.
- Use a package to create the menu structure and format it for display.

I found many packages on line to format the menu structure for display, but the two that I settled on were these:

-
-

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~68 days

Total

2

Last Release

3678d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/d3bb12da0a07ef99daa73f6e75e84bc3e2e9f90a3523ab428e54deb38643876a?d=identicon)[delatbabel](/maintainers/delatbabel)

---

Top Contributors

[![delatbabel](https://avatars.githubusercontent.com/u/2335362?v=4)](https://github.com/delatbabel "delatbabel (22 commits)")

---

Tags

laraveleloquentl5laravel5menusheirarchy

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/delatbabel-nestedmenus/health.svg)

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

###  Alternatives

[watson/validating

Eloquent model validating trait.

9723.3M47](/packages/watson-validating)[dyrynda/laravel-model-uuid

This package allows you to easily work with UUIDs in your Laravel models.

4802.8M8](/packages/dyrynda-laravel-model-uuid)[reedware/laravel-relation-joins

Adds the ability to join on a relationship by name.

2121.2M13](/packages/reedware-laravel-relation-joins)[delatbabel/elocryptfive

Automatically encrypt and decrypt Eloquent attributes with ease.

8493.0k](/packages/delatbabel-elocryptfive)[rutorika/sortable

Adds sortable behavior and ordering to Laravel Eloquent models. Grouping and many to many supported.

299992.5k14](/packages/rutorika-sortable)[rtconner/laravel-likeable

Trait for Laravel Eloquent models to allow easy implementation of a 'like' or 'favorite' or 'remember' feature.

394388.0k5](/packages/rtconner-laravel-likeable)

PHPackages © 2026

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