acid-solutions/menufactory

A tool to create cool menu with PHP
1,654
Install
composer require acid-solutions/menufactory
Latest Version:v0.0.2
PHP:>=5.4.0
Laravel:4
License:MIT
Last Updated:May 28, 2015
Links: GitHub  ·  Packagist
Maintainer: daniel-acid

Menu Factory

Create complex menu without stress.

How to install

Edit app/config/app.php Add

// 'providers'
'AcidSolutions\MenuFactory\MenuFactoryServiceProvider',

And

// 'aliases'
'MenuFactory' => 'AcidSolutions\MenuFactory\MenuFactoryFacade',

How to use

Call the factory

$menu = MenuFactory::createMenu('MenuName');

Define one or more children

$menu->add('Menu without Child');

Get html render for one menu

$menu->renderHtml();
// OR
MenuFactory::render('MenuName');
Pattern

Pattern is a decoration for label

$menu->add('Menu without Child but with pattern')->pattern('<strong>__LABEL__</strong>');
# OR
$pattern = '<strong>__LABEL__</strong>';
$menu->add('Menu without Child but with pattern1')->pattern($pattern);
$menu->add('Menu without Child but with pattern2')->pattern($pattern);
$menu->add('Menu without Child but with pattern3')->pattern($pattern);
Chained multilevel

Create multilevel menu by chaining add

$menu->add('Menu with chained child')->add('First level')->add('Second level')->add('third level')->add('Fourth level');
Multiple child with closure

Create Multiple children with closure, you've access to all options

$menu->add('Menu with multiple child defined by closure', function ($menu) {
  $menu->add('first child');
  $menu->add('second child');
  $menu->add('third child');
});

More menu? OK Let's DO ITTTT

$menu->add('Menu with multiple child with multiple child defined by closure', function ($menu) {
  $menu->add('first child', function ($menu) {
    $menu->add('first child');
    $menu->add('second child');
    $menu->add('third child');
  });
  $menu->add('second child', function ($menu) {
    $menu->add('first child');
    $menu->add('second child');
    $menu->add('third child');
  });
  $menu->add('third child', function ($menu) {
    $menu->add('first child');
    $menu->add('second child');
    $menu->add('third child');
  });
});
Allow access with Closure

Sometime you need to hide or show menu item to group of user. Use closure to defined it!

// Using Sentry::check() for this example (it will check if user is auth)
$userAuth = Sentry::check();
$menu->add('Menu with allow function')->allow(function () use ($userAuth) {
  // You can do everything you want here
  return $userAuth;
});

$menu->add('Menu with allow function (gonna be hide)')->allow(function () use ($userAuth) {
  // You can do everything you want here
  return !$userAuth;
});

// Wait, why closure if i've the value?
$menu->add('Menu with allow function (gonna be hide)')->allow($userAuth);
Option on item

To Apply option to an item (class, click, bisous)

$menu->add('Menu with Option')->option('class', 'btn');

Oh Shit i want to add btn class on the a, btn-group on the container li of the a and a dropdown-menu if this element have children...HOW!

$menu->add('Menu with Option')
  ->option('class', 'btn')
  ->option('class', 'btn-group', 'li')
  ->option('class', 'dropdown-menu', 'ul');
What's about LInk?

Oh yes! links...

$menu->add('Menu with uri')->uri('to_this_uri');

Related Packages

doctrine/dbal

Powerful PHP database abstraction layer (DBAL) with many features for database s...

641,106,524 9,700
laravel/framework

The Laravel Framework.

593,882,149 34,959
laravel/tinker

Powerful REPL for the Laravel framework.

502,645,077 7,441
laravel/serializable-closure

Laravel Serializable Closure provides an easy and secure way to serialize closur...

418,291,778 609
nunomaduro/collision

Cli error handling for console/command-line PHP applications.

394,964,158 4,660

Version History

Version Released PHP Laravel License
v0.0.2 >=5.4.0 4.* MIT
v0.0.1 >=5.4.0 4.* MIT