2017 © Pedro Peláez
 

library menu

Effortless menu building for Laravel 4

image

lukesnowden/menu

Effortless menu building for Laravel 4

  • Tuesday, February 6, 2018
  • by lukesnowden
  • Repository
  • 2 Watchers
  • 14 Stars
  • 1,401 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 5 Forks
  • 1 Open issues
  • 13 Versions
  • 7 % Grown

The README.md

lukesnowden/menu

http://luke.sno.wden.co.uk/menu for more information and for feature requests., (*1)

Usage

Very simple method of building menus from database data (id, parent id), service provider register methods for application modules and much more., (*2)

Standalone

use LukeSnowden\Menu\Menu;
include __DIR__ . '/vendor/autoload.php';

Example 1

<?php
Menu::addItem( array( 'text' => 'Home', 'URL' => '/', 'reference' => '0' ) );
echo Menu::render();
?>

Example 2 - Nesting Children

<?php
Menu::addItem( array( 'text' => 'Services', 'URL' => '/services/', 'reference' => '1', 'parent' => '0' ) );
echo Menu::render();
?>

Example 3 - Multiple Menus

<?php
Menu::addItem( array( 'text' => 'Services', 'URL' => '/services/', 'reference' => '1', 'parent' => '0' ) )->toMenu( 'main' );
echo Menu::render( 'main' );
?>

Auto classes

I have added in some of the most used and required classes for styling menus, (*3)

.first-item {}
.last-item {}
.current-root {}
.current-parent {}
.current-ancestor {}
.has-children {}

Output

<?php
Menu::addItem( array( 'text' => 'Home', 'URL' => '/menu-test-2/public/', 'reference' => '1', 'class' => 'home-icon', 'weight' => 0 ) )->toMenu( 'main' );
Menu::addItem( array( 'text' => 'Services', 'URL' => '/menu-test-2/public/services/', 'reference' => '2' ) )->toMenu( 'main' );
Menu::addItem( array( 'text' => 'Development', 'URL' => '/menu-test-2/public/services/development/', 'reference' => '3', 'parent' => '2' ) )->toMenu( 'main' );
Menu::addItem( array( 'text' => 'Design', 'URL' => '/menu-test-2/public/services/design/', 'reference' => '4', 'parent' => '2', 'weight' => 0 ) )->toMenu( 'main' );
echo Menu::render( 'main' );
?>
<ul class="nav-main">
    <li class="home-icon current first-item container node-1">
        <a href="/menu-test-2/public/">Home</a>
    </li>
    <li class=" has-children last-item container node-1">
        <a href="/menu-test-2/public/services/">Services</a>
        <ul>
            <li class=" first-item nav-node node-2">
                <a href="/menu-test-2/public/services/design/">Design</a>
            </li>
            <li class=" last-item nav-node node-2">
                <a href="/menu-test-2/public/services/development/">Development</a>
            </li>
        </ul>
    </li>
</ul>

Custom attributes

$name = false, $attributes = array(), $htmlTag = 'ul', (*4)

echo Menu::render( 'main', array( 'class' => 'nav nav-pills nav-stacked', 'role' => 'tablist' ), 'nav' );

Custom Layout Render

You may want to change the output layout (demo render class included), (*5)

Menu::addItem( array( 'text' => 'Home', 'URL' => '/menu-test-2/public/', 'reference' => '1', 'class' => 'home-icon', 'weight' => 0 ) )->toMenu( 'main' );
Menu::addItem( array( 'text' => 'Services', 'URL' => '/menu-test-2/public/services/', 'reference' => '2' ) )->toMenu( 'main' );
Menu::addItem( array( 'text' => 'Development', 'URL' => '/menu-test-2/public/services/development/', 'reference' => '3', 'parent' => '2' ) )->toMenu( 'main' );
Menu::addItem( array( 'text' => 'Design', 'URL' => '/menu-test-2/public/services/design/', 'reference' => '4', 'parent' => '2', 'weight' => 0 ) )->toMenu( 'main' );

Menu::setMenuType( 'horizontal', 'main', 'LukeSnowden\Menu\Styles' );
echo Menu::render( 'main' );

Use with third party menu UI through L4 Model

(Please note this is just a general summary of how it would work if you had 2 tables (and models) for navigations and navigation items with a standard hasMany() relationship), (*6)

<?php
$navigation = Navigation::with( 'navigationItems' )->where( 'navigation_slug', '=', 'main' )->get();
foreach( $navigation->navigationItems as $item )
{
    Menu::addItem( array( 'text' => , $item->name 'URL' => $item->url, 'reference' => $item->id, 'parent' => $item->parent_id, 'weight' => $item->order ) )->toMenu( $navigation->navigation_slug );
}
echo Menu::render( $navigation->navigation_slug );
?>

Laravel Install

Add the following to you applications composer.json file, (*7)

composer require lukesnowden/menu:dev-master

add the following to your /app/config/app.php's provider array., (*8)

'LukeSnowden\Menu\MenuServiceProvider'

add the following to your /app/config/app.php's aliases array., (*9)

'Menu'      => 'LukeSnowden\Menu\Facades\Menu'

and finally back to your terminal and run, (*10)

php composer.phar dump-autoload

The Versions

06/02 2018

dev-master

9999999-dev http://luke.sno.wden.co.uk/menu

Effortless menu building for Laravel 4

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

06/02 2018

1.4.0

1.4.0.0 http://luke.sno.wden.co.uk/menu

Effortless menu building for Laravel 4

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

20/11 2017

1.3.7

1.3.7.0 http://luke.sno.wden.co.uk/menu

Effortless menu building for Laravel 4

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

24/08 2017

1.3.6

1.3.6.0 http://luke.sno.wden.co.uk/menu

Effortless menu building for Laravel 4

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

01/02 2017

1.3.5

1.3.5.0 http://luke.sno.wden.co.uk/menu

Effortless menu building for Laravel 4

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

21/03 2016

1.3.4

1.3.4.0 http://luke.sno.wden.co.uk/menu

Effortless menu building for Laravel 4

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

15/03 2016

1.3.3

1.3.3.0 http://luke.sno.wden.co.uk/menu

Effortless menu building for Laravel 4

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

01/03 2016

1.3.2

1.3.2.0 http://luke.sno.wden.co.uk/menu

Effortless menu building for Laravel 4

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

22/02 2016

1.3.1

1.3.1.0 http://luke.sno.wden.co.uk/menu

Effortless menu building for Laravel 4

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

22/02 2016

1.3.0

1.3.0.0 http://luke.sno.wden.co.uk/menu

Effortless menu building for Laravel 4

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

22/02 2016

1.2

1.2.0.0 http://luke.sno.wden.co.uk/menu

Effortless menu building for Laravel 4

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

03/02 2015

1.1

1.1.0.0 http://luke.sno.wden.co.uk/menu

Effortless menu building for Laravel 4

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

14/07 2014

1.0

1.0.0.0 https://github.com/lukesnowden/menu/

Effortless menu building for Laravel 4

  Sources   Download

MIT

The Requires

  • php >=5.3.0