PHPackages                             radiatecode/laravel-navbar - 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. radiatecode/laravel-navbar

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

radiatecode/laravel-navbar
==========================

Laravel package to generate menus

v1.0.1(2y ago)144MITPHPPHP ^7.1|^8.0

Since Jul 3Pushed 2y ago1 watchersCompare

[ Source](https://github.com/radiatecode/laravel-navbar)[ Packagist](https://packagist.org/packages/radiatecode/laravel-navbar)[ RSS](/packages/radiatecode-laravel-navbar/feed)WikiDiscussions main Synced today

READMEChangelog (3)Dependencies (2)Versions (4)Used By (0)

Laravel Navbar
==============

[](#laravel-navbar)

This package generates navigation/navbar for laravel application. The package also provide a build in html navigation UI, it also allows you to build your own custom navigation UI.

Sample &amp; Usages
===================

[](#sample--usages)

```
$navitems = Nav::make()
    ->add('Home', route('home'), ['icon' => 'fa fa-home'])
    ->header('Adminland', function (Nav $nav) {
        $nav
            ->add('Roles', route('role-list'), ['icon' => 'fa fa-user-tag'])
            ->add('Users', route('system-user-list'), ['icon' => 'fa fa-users']);
    })
    ->header('Employee Management', function (Nav $nav) {
        $nav
            ->add('Employee', '#', ['icon' => 'fa fa-user'], function (Children $children) {
                $children
                    ->add('List', route('employee-list'), ['icon' => 'fa fa-list'])
                    ->add('Create', route('create-employee'), ['icon' => 'fa fa-plus-circle']);
            })
            ->add('Transfer', '#', ['icon' => 'fa fa-money-check-alt'], function (Children $children) {
                $children
                    ->add('List', route('transfer-list'), ['icon' => 'fa fa-list'])
                    ->add('Create', route('create-transfer'), ['icon' => 'fa fa-plus-circle']);
            });
    })
    ->render(); // array of nav items

$navbar = Navbar::navs($navitems)->render(); // navbar html
```

> **Note:** You can(should) generate the navbar in the [View Composer](https://laravel.com/docs/10.x/views#view-composers)

### Navbar In View Composer Example

[](#navbar-in-view-composer-example)

```
use RadiateCode\LaravelNavbar\Nav;
use RadiateCode\LaravelNavbar\Children;
use RadiateCode\LaravelNavbar\Facades\Navbar;

class ViewServiceProvider extends ServiceProvider
{

    public function boot()
    {
        View::composer('layouts.partials._left_nav',function(View $view){
            $navitems = Nav::make()
                ->addIf(condition: true, 'Roles', route('role-list'), ['icon' => 'fa fa-user-tag'])
                ->add('Users', route('system-user-list'), ['icon' => 'fa fa-users'])
                ->add('Employee', '#', ['icon' => 'fa fa-user'], function (Children $children) {
                    $children
                        ->addif(condition: true, 'List', route('employee-list'), ['icon' => 'fa fa-list'])
                        ->addif(condition: false, 'Create', route('create-employee'), ['icon' => 'fa fa-plus-circle']);
                })
                ->render(); // array of nav items

                // Navbar UI builder
                $navbar = Navbar::navs($navitems));

                // Now attach the $navbar to your view.
                $view->with('navbar', $navbar->render();
        });

        // Or you can use `class based view composer`. place the Navbar generator code inside the compose().
        View::composer('layouts.partials._left_nav', NavComposer::class);
    }

}
```

In **\_left\_nav** partials

```

        {!! $navbar !!}

```

**Output**

[![Stats](img/navbar.png)](img/navbar.png)

Requirements
============

[](#requirements)

- [PHP &gt;= 7.1](https://www.php.net/)
- [Laravel 5.7|6.x|7.x|8.x|9.x](https://github.com/laravel/framework)
- [JQuery](https://jquery.com/) \[Optional for custom navbar UI styling\]
- [Bootstrap](https://getbootstrap.com/) \[Optional for custom navbar UI styling\]

Installation
============

[](#installation)

You can install the package via composer:

```
composer require radiatecode/laravel-navbar

```

Publish config file (optional)

```
php artisan vendor:publish --provider="RadiateCode\LaravelNavbar\NavbarServiceProvider" --tag="navbar-config"

```

Usage
=====

[](#usage)

Nav available methods
---------------------

[](#nav-available-methods)

### 1. Header : it is use to group certain nav items

[](#1-header--it-is-use-to-group-certain-nav-items)

Syntax:

`header(string $name, Closure $closure, array $attributes = [])` : 1st arg is the name of the header, 2nd arg is a closure to add nav items under the header, 3rd is for any extra attributes (ex: icon, class etc.)

```
// example
Nav::make()
->header('Adminland', function (Nav $nav) {
    // add nav items under the Adminland header
})
```

### 2. Add: add nav items

[](#2-add-add-nav-items)

Syntax:

`add(string $title, string $url, ?array $attributes = null, ?callable $children = null)`: 1st arg name of the nav item, 2nd arg is the nav url, 3rd is for any extra attributes (ex: nav icon, classes), 4th arg is for if you want to add children nav.

```
//Example 1
$navitems = Nav::make()
            ->add('Roles', route('role-list'), ['icon' => 'fa fa-user-tag'])
            ->add('Users', route('user-list'), ['icon' => 'fa fa-users'])
            ->render();

// Example 2: with header
$navitems = Nav::make()
        ->header('Adminland', function (Nav $nav) {
            $nav
                ->add('Roles', route('role-list'), ['icon' => 'fa fa-user-tag'])
                ->add('Users', route('system-user-list'), ['icon' => 'fa fa-users'])
                ->add('Settings', route('system-settings'), ['icon' => 'fa fa-wrench'])
        })
        ->render();
```

### 3. Add If: Conditionally add nav

[](#3-add-if-conditionally-add-nav)

Syntax:

`addIf($condition, string $title, string $url, array $attributes = [], ?callable $configure = null)`: 1st arg is the condition bool or closure return bool, 2nd name of the nav, 3rd nav url, 4th extra attributes, 5th a closure for adding children nav.

```
//Example 1
$navitems = Nav::make()
        ->addIf(true, 'Roles', route('role-list'), ['icon' => 'fa fa-user-tag'])
        ->addIf(false, 'Users', route('user-list'), ['icon' => 'fa fa-users'])
        ->render();

//Example 2: with header
        $navitems = Nav::make()
        ->header('Adminland', function (Nav $nav) {
            $nav
                ->addIf(true, 'Roles', route('role-list'), ['icon' => 'fa fa-user-tag'])
                ->addIf(false, 'Users', route('system-user-list'), ['icon' => 'fa fa-users'])
                ->addIf(true, 'Settings', route('system-settings'), ['icon' => 'fa fa-wrench'])
        })
        ->render();
```

### 4. Chidlren nav: you can add children navs

[](#4-chidlren-nav-you-can-add-children-navs)

You have already noticed how we added children nav. We can also conditionally add children nav

```
// Example
$navitems = Nav::make()
->header('Employee Management', function (Nav $nav) {
    $nav
        ->add('Employee', '#', ['icon' => 'fa fa-user'], function (Children $children) {
            $children
                ->add('List', route('employee-list'), ['icon' => 'fa fa-list'])
                ->add('Create', route('create-employee'), ['icon' => 'fa fa-plus-circle']);
        })
        ->add('Transfer', '#', ['icon' => 'fa fa-money-check-alt'], function (Children $children) {
            // we can also conditionally add children nav
            $children
                ->addIf(true, 'List', route('transfer-list'), ['icon' => 'fa fa-list'])
                ->addIf(true, 'Create', route('create-transfer'), ['icon' => 'fa fa-plus-circle']);
        })
})
->render();
```

### 5. Render: and the render method to get the array of nav items

[](#5-render-and-the-render-method-to-get-the-array-of-nav-items)

```
// render() result sample
[
    "home" => [
        "title" => "Home",
        "url" => "http://hrp.test/",
        "attributes" => [
            "icon" => 'fa fa-home'
        ],
        "is_active" => false,
        "type" => "menu",
        "children" => [] // no children
    ],
    "adminland" => [ // header
        "title" => "Adminland",
        "attributes" => [],
        "type" => "header",
        "nav-items" => [ // nav items under the adminland header
            'roles' => [
                "title" => "Roles",
                "url" => "http://hrp.test/role-list",
                "attributes" => [
                    "icon" => 'fa fa-user-tag'
                ],
                "is_active" => false,
                "type" => "menu",
                "children" => [] // no children
            ],
            'user' => [
                "title" => "User",
                "url" => "http://hrp.test/system-user-list",
                "attributes" => [
                    "icon" => 'fa fa-users'
                ],
                "is_active" => false,
                "type" => "menu",
                "children" => [] // no children
            ]
        ]
    ],
    "employee-management"  => [ // header
        "title" => "Employee Management",
        "attributes" => [],
        "type" => "header",
        "nav-items" => [ // nav items under the employee managment
            'employee' => [
                "title" => "Employee", // parent nav
                "url" => "#",
                "attributes" => [
                    "icon" => 'fa fa-user'
                ],
                "is_active" => false,
                "type" => "menu",
                "children" => [ // children nav items of employee nav
                    'list' => [
                        "title" => "List",
                        "url" => "http://hrp.test/employee-list",
                        "attributes" => [
                            "icon" => 'fa fa-list'
                        ],
                        "is_active" => false,
                        "type" => "menu",
                        "children" => []
                    ],
                    'create' => [
                        "title" => "Create",
                        "url" => "http://hrp.test/create-employee",
                        "attributes" => [
                            "icon" => 'fa fa-plus-circle'
                        ],
                        "is_active" => false,
                        "type" => "menu",
                        "children" => []
                    ]
                ]
            ]
        ]
    ],
]
```

Navbar UI Builder
-----------------

[](#navbar-ui-builder)

`Laravel-Navbar` provide a built in navbar UI builder so that you can easily integrate the UI with your app.

> Note: You can built your own custom Navbar UI by defining custom [Navbar Presenter](#navbar-presenter). Or, you can comes up with your own approch to show navbar.

**Example:** see the view composer [example](#navbar-in-view-composer-example)

### Methods

[](#methods)

Available methods of the builder

- `navs(array $navItems)` : generated nav items
- `render()` : Render the html
- `navActiveScript()` : Nav active script usefull if you want to active the current nav item in the front-end by Js(JQuery). It has another benefit, if you cache the generated navbar this script will help you to active your current nav because the back-end active function only active once before cache, after cached it always show that same active nav. So it is **recommended** if you want to cache your navbar you should disable back-end `nav-active` from the [Config](#Config) and use this script in the front-end. ```
    // Example of nav active script
    $navbar = Navbar::navs($navitems);

    $view->with('navbar', $navbar->render())
         ->with('navScript',$navbar->navActiveScript());
    ```

    ```

        {!! $navbar !!}

    @prepend('js')
        {!! $navScript !!}
    @endprepend

    ```

    Or, you can add it to you script partials ```

    {!! RadiateCode\LaravelNavbar\Facades\Navbar::navActiveScript(); !!}

        // other js code

    ```

Navbar Presenter
----------------

[](#navbar-presenter)

Navbar presenter is nothing but a class which contain some functionality to generate navbar html. Under the hood the [Navbar builder](#navbar-ui-builder) use this presenter. You can use your own custom presenter. If you use custom presenter make sure you have add it in your [Navbar Config](#config)

Config
------

[](#config)

```
 /**
 * Presenter for navbar style
 *
 * [HTML presenter]
 */
'nav-presenter' => NavbarPresenter::class,

/**
 * It will set active to requested/current nav
 *
 * [Note: if you want to set nav active by front-end (Js/Jquery)
 * Or, if you cached your rendered navbar, then you should disable it]
 */
'enable-nav-active' => true
```

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.

Credits
-------

[](#credits)

- [Noor Alam](https://github.com/radiatecode)
- [All Contributors](https://github.com/radiatecode/laravel-route-permission/contributors)

License
-------

[](#license)

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

###  Health Score

25

—

LowBetter than 35% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity55

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 ~186 days

Total

3

Last Release

1087d ago

Major Versions

v0.1.0 → v1.0.02023-06-05

### Community

Maintainers

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

---

Top Contributors

[![radiatecode](https://avatars.githubusercontent.com/u/51012746?v=4)](https://github.com/radiatecode "radiatecode (14 commits)")

---

Tags

laravel-menuLaravel-NavigationLaravel Menuslaravel-site-menularavel-navbar

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/radiatecode-laravel-navbar/health.svg)

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

###  Alternatives

[spatie/laravel-menu

Html menu generator for Laravel

9822.9M11](/packages/spatie-laravel-menu)[spatie/laravel-navigation

Manage menus, breadcrumbs, and other navigational elements in Laravel apps

5831.2M16](/packages/spatie-laravel-navigation)[awes-io/navigator

🧿 Build navigation or menu for Laravel and Awes.io. Unlimit complexity and depth of the menu.

4922.8k](/packages/awes-io-navigator)[laravel-enso/menus

Menu management for Laravel Enso

1644.0k25](/packages/laravel-enso-menus)[salahhusa9/laravel-menu

Html menu generator for Laravel

165.0k](/packages/salahhusa9-laravel-menu)

PHPackages © 2026

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