PHP code example of sclaravel / menus

1. Go to this page and download the library: Download sclaravel/menus library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

sclaravel / menus example snippets


Menu::create('navbar', function($menu) {
	// define your menu items here
});

Menu::create('navbar', function($menu) {
            // URL , Title,  Attributes
  $menu->url('home', 'Home', ['target' => 'blank']);
});

Menu::create('navbar', function($menu) {
	$menu->route(
		'users.show', // route name
		'View Profile', // title
		['id' => 1], // route parameters
		['target' => 'blank'] // attributes
	);
});

Menu::create('navbar', function($menu) {
	$menu->add([
		'url' => 'about',
		'title' => 'About',
		'attributes' => [
			'target' => '_blank'
		]
	]);

	$menu->add([
		'route' => ['profile', ['user' => 'gravitano']],
		'title' => 'Visit My Profile',
		'attributes' => [
			'target' => '_blank'
		]
	]);
});

Menu::create('menu1', function($menu) {

	$menu->route('home', 'Home');

	$menu->url('profile', 'Profile');
});

Menu::create('menu2', function($menu) {
	$menu->route('home', 'Home');

	$menu->url('profile', 'Profile');
});

Menu::create('navbar', function($menu) {
	$menu->setPresenter('TysonLaravel\Menus\Presenters\Bootstrap\NavTabPresenter');
});

Menu::render('navbar', 'navbar-right');

Menu::render('navbar', 'TysonLaravel\Menus\Presenters\Bootstrap\NavPillsPresenter');

use TysonLaravel\Menus\Presenters\Presenter;

class ZurbTopBarPresenter extends Presenter {
	/**
	 * {@inheritdoc }
	 */
	public function getOpenTagWrapper()
	{
		return  PHP_EOL . '<section class="top-bar-section">' . PHP_EOL;
	}

	/**
	 * {@inheritdoc }
	 */
	public function getCloseTagWrapper()
	{
		return  PHP_EOL . '</section>' . PHP_EOL;
	}

	/**
	 * {@inheritdoc }
	 */
	public function getMenuWithoutDropdownWrapper($item)
	{
		return '<li'.$this->getActiveState($item).'><a href="'. $item->getUrl() .'">'.$item->getIcon().' '.$item->title.'</a></li>';
	}

	/**
	 * {@inheritdoc }
	 */
	public function getActiveState($item)
	{
		return \Request::is($item->getRequest()) ? ' class="active"' : null;
	}

	/**
	 * {@inheritdoc }
	 */
	public function getDividerWrapper()
	{
		return '<li class="divider"></li>';
	}

	/**
	 * {@inheritdoc }
	 */
	public function getMenuWithDropDownWrapper($item)
	{
		return '<li class="has-dropdown">
		        <a href="#">
		         '.$item->getIcon().' '.$item->title.'
		        </a>
		        <ul class="dropdown">
		          '.$this->getChildMenuItems($item).'
		        </ul>
		      </li>' . PHP_EOL;
		;
	}
}


Menu::create('zurb-top-bar', function($menu) {
	$menu->setPresenter('ZurbTopBarPresenter');
});

return array(
	'navbar'		=>	'TysonLaravel\Menus\Presenters\Bootstrap\NavbarPresenter',
	'navbar-right'	=>	'TysonLaravel\Menus\Presenters\Bootstrap\NavbarRightPresenter',
	'nav-pills'		=>	'TysonLaravel\Menus\Presenters\Bootstrap\NavPillsPresenter',
	'nav-tab'		=>	'TysonLaravel\Menus\Presenters\Bootstrap\NavTabPresenter',

	'zurb-top-bar'	=>	'ZurbTopBarPresenter',
);

Menu::create('zurb-top-bar', function($menu) {
	$menu->style('zurb-top-bar');
});

Menu::render('navbar');

Menu::get('navbar');

$menu = Menu::instance('zurb-top-bar');

// You can also make additions to the menu again

$menu->add(['title' => 'Settings', 'route' => 'settings']);

$menu->url('profile', 'Profile');

$menu->route('settings', 'Settings');

php artisan vendor:publish

Menu::make('navbar', function($menu) {
	// define your menu items here
});

Menu::create('navbar', function($menu) {
	$menu->url('/', 'Home');
	$menu->dropdown('Settings', function ($sub) {
		$sub->url('settings/account', 'Account');
		$sub->url('settings/password', 'Password');
		$sub->url('settings/design', 'Design');
	});
});

Menu::create('navbar', function($menu)
{
	$menu->url('/', 'Home');
	$menu->dropdown('Account', function ($sub) {
		$sub->url('profile', 'Visit My Profile');
		$sub->dropdown('Settings', function ($sub) {
			$sub->url('settings/account', 'Account');
			$sub->url('settings/password', 'Password');
			$sub->url('settings/design', 'Design');
		});
		$sub->url('logout', 'Logout');
	});
});

Menu::create('navbar', function($menu) {
	$menu->url('/', 'Home')
	$menu->dropdown('Settings', function ($sub) {
		$sub->header('ACCOUNT');
		$sub->url('/settings/design', 'Design');
		$sub->divider();
		$sub->url('logout', 'Logout');
	});
});

Menu::create('navbar', function($menu) {
	// url, title, order, attributes
	$menu->url('/', 'Home', 1);
	// url, title, route parameters, order, attributes
	$menu->route('/', 'About', ['user' => '1'], 2);
	// title, order, callback attributes
	$menu->dropdown('Settings', function ($sub) {
		$sub->header('ACCOUNT');
		$sub->url('/settings/design', 'Design');
		$sub->divider();
		$sub->url('logout', 'Logout');
	}, 3);
});

Menu::create('navbar', function($menu) {
	$menu->url('/', 'Home', ['icon' => 'fa fa-dashboard'])->order(1);
	
	$menu->route('/', 'About', ['user' => '1'], ['icon' => 'fa fa-user'])->order(2);
	
	$menu->dropdown('Settings', function ($sub) {
		$sub->header('ACCOUNT');
		$sub->url('/settings/design', 'Design');
		$sub->divider();
		$sub->url('logout', 'Logout');
	})->order(3);
});

// File: config/menus.php
return [
	'ordering' => true
];

Menu::create('navbar', function($menu) {
	// disable menu ordering
	$menu->enableOrdering();

	// disable menu ordering
	$menu->disableOrdering();
});

Menu::create('navbar', function($menu) {
	$menu->style('nav-pills');
});

$menu = Menu::instance('sidebar');

$menu->url('profile', 'Profile');

$menu->whereTitle('Profile', function ($sub) {
	$sub->url('foo', 'Foo');
});

// add childs menu

Menu::modify('navbar', function($menu) {
	$menu->add([
		'title' => 'Foo',
		'url' => 'bar',
	]);
});

Menu::create('navbar', function($menu) {
  $menu->dropdown('Settings', function ($sub) {
    $sub->url('user-management', 'User management')->subActive(['edit-user', 'create-user']);
  });
});