2017 © Pedro Peláez
 

library laravel-menu

Make it easy to create navigation menus on Laravel

image

nurmanhabib/laravel-menu

Make it easy to create navigation menus on Laravel

  • Friday, July 6, 2018
  • by nurmanhabib
  • Repository
  • 1 Watchers
  • 0 Stars
  • 16 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 5 Versions
  • 700 % Grown

The README.md

Welcome to Laravel Menu!

Generate multi navigation menus with unique names, can be displayed anywhere. Custom templating. Support Laravel 5, 6, 7., (*1)

Alt image, (*2)


Installation

Installation with Composer

Simply execute the following command, (*3)

composer require nurmanhabib/laravel-menu

Register Service Provider and Facade

Add Nurmanhabib\LaravelMenu\MenuServiceProvider to the file in config/app.php in array with key providers., (*4)

'providers' => [
    ...,
    ...,

    Nurmanhabib\LaravelMenu\MenuServiceProvider::class,
],

Add Nurmanhabib\LaravelMenu\Facades\Menu to the file in config/app.php in array with key aliases., (*5)

'aliases' => [
    ...,
    ...,

    'Menu' => Nurmanhabib\LaravelMenu\Facades\Menu::class,
],

Quick Example

You can create in the routes files, middleware, or service providers that you custom yourself as needed., (*6)

<?php

Menu::make('sidebar', function ($menu) {
    Menu::link('Home', 'home')->setIcon('fas fa-home');
    Menu::link('Article', 'articles')->setIcon('fas fa-newspaper')
        ->setData([
            'badge' => [
                'type' => 'warning',
                'text' => '16'
            ]
        ]);

    Menu::link('Comment', 'comments')->setIcon('fas fa-comments')
        ->setData([
            'badge' => [
                'type' => 'primary',
                'text' => 'New'
            ]
        ]);

    Menu::dropdown('Services', function () {
        Menu::link('Service 1', 'services/one');
        Menu::link('Service 2', 'services/two');
    });

    Menu::heading('Account');

    Menu::link('Change Password')->setIcon('fas fa-key');
    Menu::logout()->setIcon('fas fa-sign-out-alt');
});

<?php

Menu::make('account', function () {
    Menu::link('Me', 'me', 'view-dashboard');

    Menu::separate();

    Menu::link('Change Password', url('change-password'), 'view-dashboard');
    Menu::logout();

    // Alternative to
    // Menu::link('Logout', 'logout', 'signout')->setData(['method' => 'POST']);
});

Make From Array

You might be able to make it from another data source (for example: a database) and then process it into array data and turn it into a menu., (*7)

<?php

$items = [
     [
         'text' => 'Home',
         'url' => '/'
     ],
     [
         'text' => 'Berita',
         'url' => 'berita',
         'match' => '/berita*'
     ],
     [
         'type' => 'separator'
     ],
     [
         'text' => 'Kategori',
         'child' => [
             [
                 'text' => 'Teknologi',
                 'url' => 'kategori/teknologi'
             ],
             [
                 'text' => 'Otomotif',
                 'url' => 'kategori/otomotif'
             ],
             [
                 'text' => 'Lifestyle',
                 'child' => [
                     [
                         'text' => 'Pria',
                         'url' => 'lifestyle-pria'
                     ],
                     [
                         'text' => 'Wanita',
                         'url' => 'lifestyle-wanita'
                     ],
                 ]
             ],
         ]
     ],
     [
         'type' => 'heading',
         'text' => 'Configuration'
     ],
     [
         'text' => 'Account',
         'child' => [
             [
                 'text' => 'Change Password',
                 'url' => 'change-password'
             ],
             [
                 'text' => 'Logout',
                 'url' => 'logout'
             ],
         ]
     ],
 ];

Menu::makeFromArray('sidebar', $items);

// or

Menu::make('sidebar', function () use ($items) {
    Menu::arrays($items);
});

Set View

Menu::get('sidebar')->setView('admin-lte');

Render to View

{!! Menu::get('sidebar') !!}

You can also call with the menu() helpers, (*8)

{!! menu()->get('sidebar') !!}

or, (*9)

{!! menu('sidebar') !!}

Custom View

To be able to customize the navigation with view, (*10)

Menu::get('sidebar')->setView('view.name');

Available default views:, (*11)

'views' => [
    'simple' => 'menus::simple.menu',
    'bs-nav-stacked' => 'menus::bs-nav-stacked.menu',
    'sbadmin2' => 'menus::sbadmin2.menu',
    'adminto' => 'adminto::menus.sidebar.menu',
    'admin-lte' => 'menus::admin-lte.menus',
]

Then you can customize view.name and receive $menu variable Nurmanhabib\Navigator\NavCollection, (*12)

<ul>
  @foreach ($menu->getItems() as $item)
    @if ($item->getType() == 'heading')
      <li class="text-muted">{{ $item->getText() }}</li>
    @elseif ($item->getType() == 'separator')
      <li class="text-muted">---</li>
    @else
      @if ($item->hasChild())
        <li class="has_sub">
          <a href="javascript:void(0)">
            <i class="={{ $item->getIcon() }}"></i> {{ $item->getText() }}
            <span class="menu-arrow"></span>
          </a>

          @include('view.name', ['menu' => $item->getChild()])
        </li>
      @else
        @if ($item->isActive())
          <li class="active">
            <a href="{{ $item->getUrl() }}">
              <i class="{{ $item->getIcon() }}"></i> {{ $item->getText() }}
            </a>
          </li>
        @else
          <li>
            <a href="{{ $item->getUrl() }}">
              <i class="{{ $item->getIcon() }}"></i> {{ $item->getText() }}
            </a>
          </li>
        @endif
      @endif
    @endif
  @endforeach
</ul>

Custom Renderer

use Nurmanhabib\LaravelMenu\Renders\NavViewRender;

Menu::get('sidebar')->setRenderer(new NavViewRender('view.name'));

API

$nav->getText();
$nav->getUrl();
$nav->getIcon();
$nav->isActive();
$nav->isVisible();
$nav->hasChild();
$nav->getChild();
$collection->addHeading();
$collection->addHome();
$collection->addSeparator();
$collection->addLink('Text', 'link', 'icon');
$collection->addParent('Text Parent', callback($child), 'icon', '#');
$collection->add($nav);
$collection->getItems();

Contributing

I apologize if the documentation is still not perfect, if you are willing to contribute to the documentation please do a Pull Request. We also feel happy if we want to contribute to open source., (*13)

The Versions

06/07 2018

dev-master

9999999-dev

Make it easy to create navigation menus on Laravel

  Sources   Download

MIT

The Requires

 

navigation navbar menu sidebar laravel menu navigator laravel navigation

06/07 2018

4.1.1

4.1.1.0

Make it easy to create navigation menus on Laravel

  Sources   Download

MIT

The Requires

 

navigation navbar menu sidebar laravel menu navigator laravel navigation

05/07 2018

4.1.0

4.1.0.0

Make it easy to create navigation menus on Laravel

  Sources   Download

MIT

The Requires

 

navigation navbar menu sidebar laravel menu navigator laravel navigation