nurmanhabib/laravel-menu
Composer 安装命令:
composer require nurmanhabib/laravel-menu
包简介
Make it easy to create navigation menus on Laravel
README 文档
README
Generate multi navigation menus with unique names, can be displayed anywhere. Custom templating. Support Laravel 5, 6, 7.
Installation
Installation with Composer
Simply execute the following command
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.
'providers' => [ ..., ..., Nurmanhabib\LaravelMenu\MenuServiceProvider::class, ],
Add Nurmanhabib\LaravelMenu\Facades\Menu to the file in config/app.php in array with key aliases.
'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.
<?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.
<?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
{!! menu()->get('sidebar') !!}
or
{!! menu('sidebar') !!}
Custom View
To be able to customize the navigation with view
Menu::get('sidebar')->setView('view.name');
Available default views:
'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
<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
$nav->getText(); $nav->getUrl(); $nav->getIcon(); $nav->isActive(); $nav->isVisible(); $nav->hasChild(); $nav->getChild();
NavCollection
$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.
nurmanhabib/laravel-menu 适用场景与选型建议
nurmanhabib/laravel-menu 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 306 次下载、GitHub Stars 达 12, 最近一次更新时间为 2017 年 09 月 21 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「menu」 「navigation」 「navbar」 「sidebar」 「Laravel Navigation」 「navigator」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 nurmanhabib/laravel-menu 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 nurmanhabib/laravel-menu 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 nurmanhabib/laravel-menu 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A block to display a list of links to child pages, or pages in current level
A Symfony extension to get active class base on current bundle/controller/action
Symfony NavBarBundle
Generate navigator or menu with NavCollection
Bulma Navbar component navwalker for Sage 9 based themes
Bootstrap 4 Navbar component navwalker for Sage 9 based themes
统计信息
- 总下载量: 306
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 12
- 点击次数: 9
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-09-21
