PHPackages                             rspeekenbrink/laravel-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. rspeekenbrink/laravel-menu

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

rspeekenbrink/laravel-menu
==========================

Simple menu generation in Laravel

1.4.0(1y ago)164.3k↓50%4MITPHPPHP ^7.2|^8.0CI failing

Since Oct 9Pushed 1y ago1 watchersCompare

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

READMEChangelog (10)Dependencies (7)Versions (14)Used By (0)

Laravel Menu
============

[](#laravel-menu)

[![Latest Version on Packagist](https://camo.githubusercontent.com/9214f69564f01135f0ada21bfa9cadb590f49b7c9f59498dbf06a03db70f679d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f72737065656b656e6272696e6b2f6c61726176656c2d6d656e752e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/rspeekenbrink/laravel-menu)[![Total Downloads](https://camo.githubusercontent.com/7fb8126126c526c795726cc83b79fbddc1fda350ee4ea59c45957a5c87eca935/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f72737065656b656e6272696e6b2f6c61726176656c2d6d656e752e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/rspeekenbrink/laravel-menu)

Create menu objects server-sided without sweat for Front-End adoption.

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

[](#installation)

You can install the package via composer:

```
composer require rspeekenbrink/laravel-menu
```

Usage
-----

[](#usage)

A default menu will already be registered and bound to the `Menu` facade. You can add items to the menu like this:

```
Menu::add('itemName', '/');

// Menu::toArray() Output:
[
    [
        'name' => 'itemName',
        'route' => '/',
        'active' => true,
    ]
]
```

**The itemName should be unique within the menu since this is the identifier of the item in the Menu.**

### Route attribute and Active state

[](#route-attribute-and-active-state)

The route can be an absolute route like `'/dashboard/profile'` or a name of a route like `'dashboard.index'` for the automatic active state checking to work properly. If you want to use route names we recommend you to use [Ziggy](https://github.com/tightenco/ziggy) to convert the names to URLs in your front-end.

The active attribute is a boolean that will be true if the route matches the route of the current request (path or name wise).

### Nested Routes

[](#nested-routes)

To create nested items you could use the following:

```
Menu::add('dashboard', '/')->addChildren(function () {
    Menu::add('stats', '/stats');
    Menu::add('profile', '/profile');
});

// Menu::toArray() Output:
[
    [
        'name' => 'dashboard',
        'route' => '/',
        'active' => true,
        'children' => [
            [
                'name' => 'dashboard.stats',
                'route' => '/stats',
                'active' => false,
            ],
            [
                'name' => 'dashboard.profile',
                'route' => '/profile',
                'active' => false,
            ]
        ]
    ]
]
```

### Attributes

[](#attributes)

You can pass attributes to the MenuItem to define values like Title or anything else you desire;

```
Menu::add('itemName', '/', ['title' => 'Dashboard', 'someAttribute' => 231, 'another' => 'value2']);

// Menu::toArray() Output:
[
    [
        'name' => 'itemName',
        'route' => '/',
        'active' => true,
        'title' => 'Dashboard',
        'someAttribute' => 231,
        'another' => 'value2,
    ]
]
```

### Adding items condition wise or via Auth Guards

[](#adding-items-condition-wise-or-via-auth-guards)

If you would like to add menu items conditionwise, for example only add a menu item if a user is logged in, you can do it like this:

```
Menu::addIf($conditionOrClosure, 'itemName', $route, $attributes);
```

Or pass a Auth Guard:

```
Menu::addIfCan('MyAuthGuard', 'itemName', $route, $attributes);
```

### Usage with InertiaJS

[](#usage-with-inertiajs)

The main purpose of this package is to create Menu objects that can be adopted easily by the Front-End. One of the easiest ways to transfer the objects from the back to the front is by using [InertiaJS](https://inertiajs.com/).

```
Inertia::share([
    'menu' => function () {
        return Menu::toArray();
    }
]);
```

Then for example in your inertia-vue layout template;

```

                     {{ item.title }}

                      {{ child.title }}

```

Testing
-------

[](#testing)

```
composer test
```

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.

License
-------

[](#license)

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

###  Health Score

43

—

FairBetter than 91% of packages

Maintenance43

Moderate activity, may be stable

Popularity30

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity70

Established project with proven stability

 Bus Factor1

Top contributor holds 93.4% 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 ~177 days

Recently: every ~224 days

Total

12

Last Release

453d ago

Major Versions

0.4.0 → 1.0.02020-09-11

PHP version history (2 changes)0.1.0PHP ^7.2

1.0.1PHP ^7.2|^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/9e272af6fe1744b2ffed9a88bf195543e3070cf14f941a394572231a84893dbe?d=identicon)[RSpeekenbrink](/maintainers/RSpeekenbrink)

![](https://avatars.githubusercontent.com/u/31687602?v=4)[Lex de Willigen](/maintainers/lexdewilligen)[@lexdewilligen](https://github.com/lexdewilligen)

---

Top Contributors

[![RSpeekenbrink](https://avatars.githubusercontent.com/u/7093216?v=4)](https://github.com/RSpeekenbrink "RSpeekenbrink (71 commits)")[![lexdewilligen](https://avatars.githubusercontent.com/u/31687602?v=4)](https://github.com/lexdewilligen "lexdewilligen (4 commits)")[![StyleCIBot](https://avatars.githubusercontent.com/u/11048387?v=4)](https://github.com/StyleCIBot "StyleCIBot (1 commits)")

---

Tags

front-endjavascriptlaravelmenu

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[barryvdh/laravel-ide-helper

Laravel IDE Helper, generates correct PHPDocs for all Facade classes, to improve auto-completion.

14.9k123.0M687](/packages/barryvdh-laravel-ide-helper)[spatie/laravel-enum

Laravel Enum support

3655.4M31](/packages/spatie-laravel-enum)[psalm/plugin-laravel

Psalm plugin for Laravel

3274.9M308](/packages/psalm-plugin-laravel)[orchestra/canvas

Code Generators for Laravel Applications and Packages

21017.2M158](/packages/orchestra-canvas)[illuminate/pipeline

The Illuminate Pipeline package.

9446.6M213](/packages/illuminate-pipeline)[illuminate/pagination

The Illuminate Pagination package.

10532.5M862](/packages/illuminate-pagination)

PHPackages © 2026

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