PHP code example of nurmanhabib / laravel-menu
1. Go to this page and download the library: Download nurmanhabib/laravel-menu 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/ */
nurmanhabib / laravel-menu example snippets
'providers' => [
...,
...,
Nurmanhabib\LaravelMenu\MenuServiceProvider::class,
],
'aliases' => [
...,
...,
'Menu' => Nurmanhabib\LaravelMenu\Facades\Menu::class,
],
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');
});
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']);
});
$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);
});
Menu::get('sidebar')->setView('admin-lte');
Menu::get('sidebar')->setView('view.name');
'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',
]
use Nurmanhabib\LaravelMenu\Renders\NavViewRender;
Menu::get('sidebar')->setRenderer(new NavViewRender('view.name'));
$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();
html
{!! Menu::get('sidebar') !!}
html
{!! menu('sidebar') !!}
html
<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>
@