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

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

kamilsawicki/laravel-menu-builder
=================================

Menu builder for Laravel

00PHP

Since Oct 2Pushed 2y ago1 watchersCompare

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

READMEChangelogDependenciesVersions (1)Used By (0)

Laravel Menu Builder
====================

[](#laravel-menu-builder)

About
-----

[](#about)

Simple Laravel menu builder for Laravel 10 applications.

Requirements
------------

[](#requirements)

PHP &gt;= 8.2, Tidy extension.

How to use
----------

[](#how-to-use)

### Installation

[](#installation)

Add to your providers list in app.php `\KamilSawicki\LaravelMenuBuilder\Providers\LaravelMenuBuilderProvider::class,`.

### Usage

[](#usage)

Just extend `AbstractMenuBuilder` and override `build` and `identifier` methods.

### AbstractMenuBuilder class

[](#abstractmenubuilder-class)

#### build(): void

[](#build-void)

Contains definition of menu items. You can add new object with Item::class using self::add() method.

#### identifier(): string

[](#identifier-string)

Should return string, that is used (by default) as id of root element and cache key.

#### string $itemTemplate

[](#string-itemtemplate)

Path to blade item template used on first level of menu.

#### string $childTemplate

[](#string-childtemplate)

Path to blade item template used on another level of menu. If null, used `$itemTemplate`.

#### string $wrapperTemplate

[](#string-wrappertemplate)

Path to blade template, that wrapping whole items.

#### string $childWrapperTemplate

[](#string-childwrappertemplate)

Path to blade template, that wrapping whole sub-levels items. If null, used `$wrapperTemplate`.

### Item class

[](#item-class)

#### new(string $label, string $path = '#', bool $external = false): self

[](#newstring-label-string-path---bool-external--false-self)

Static constructor for class. Accepts arguments `label` (required), `path` (optional, default `#`) - route name or URL if `external` (optional, default `false`) is `true`.

#### if(bool $expression): self (shortcut) and setToRender(bool $toRender): self

[](#ifbool-expression-self-shortcut-and-settorenderbool-torender-self)

Accept boolean expression define that item should not be filtered on rendering.

#### setClass(string $class): self

[](#setclassstring-class-self)

HTML class on `` element.

#### addChildren(Item $child): self and setChildren(array|Collection $children): self

[](#addchildrenitem-child-self-and-setchildrenarraycollection-children-self)

Add Item::class to sub-level of tree menu. `addChildren`

#### setAttr(array&lt;string, string&gt; $attr): self

[](#setattrarraystring-string-attr-self)

List of custom attributes on `` element. Rendered as `key="value"`

#### setOptions(array&lt;string, string&gt; $options): self

[](#setoptionsarraystring-string-options-self)

Custom variables passed to view, that can be used in custom templates.

Example
-------

[](#example)

```
class ExampleMenuBuilder extends AbstractMenuBuilder
{
    protected function build(): void {
        $this->add(Item::new('Item 1', 'page_one'));
        $this->add(Item::new('Item 2', 'page_two'));
        $this->add(Item::new('Folder')
            ->addChildren(Item::new('SubItem 1', 'folder.sub_page_one'))
            ->addChildren(Item::new('SubItem 2', 'folder.sub_page_two'))
        );
        $this->add(Item::new('Hidden')->if(1 == 0));
        $this->add(Item::new('Red class')->setClass('red'));
        $this->add(Item::new('Custom view var')->setOptions([
            'custom-var' => 'test',
        ]));
        $this->add(Item::new('Custom attribute')
            ->setAttr(['custom-attr' => 'custom value'])
        );
    }

    protected function identifier(): string {
        return 'example_menu';
    }
}
```

will be rendered as

```

        Item 1

        Item 2

        Folder

                SubItem 1

                SubItem 2

        Red class

        Custom view var

        Custom attribute

```

###  Health Score

12

—

LowBetter than 0% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity0

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity21

Early-stage or recently created project

 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.

### Community

Maintainers

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

---

Top Contributors

[![KamilSawicki](https://avatars.githubusercontent.com/u/23055913?v=4)](https://github.com/KamilSawicki "KamilSawicki (1 commits)")

### Embed Badge

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

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

PHPackages © 2026

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