felixdorn / laravel-navigation
为您的Laravel应用程序创建导航菜单。
1.0.0
2022-09-18 09:45 UTC
Requires
- php: ^8.1
- felixdorn/laravel-url-resolver: ^2.0
- honda/url-pattern-matcher: ^1.0.1
- illuminate/contracts: ^9.30
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3
- orchestra/testbench: ^7.7
- pestphp/pest: ^1.0.5
- pestphp/pest-plugin-mock: ^1.0
- phpstan/phpstan: ^1.8.5
- symfony/var-dumper: ^6.1
This package is auto-updated.
Last update: 2024-09-09 15:21:16 UTC
README
为您的Laravel应用程序创建导航菜单,与Inertia无缝兼容。
特性
- Inertia支持
- 条件添加部分/项。
- 轻松指定路由是否活跃
- 为项添加元数据
安装
需要 PHP 8.0+
您可以通过composer安装此包
composer require felixdorn/laravel-navigation
使用方法
创建导航栏
use Felix\Navigation\Navigation; Navigation::register('dashboardSidebar', function (Navigation $navigation) { });
检索导航栏
use Felix\Navigation\Navigation; Navigation::dashboardSidebar()->toArray(); // alternatively, to get the raw tree underneath: Navigation::dashboardSidebar()->tree();
条件渲染项
use Felix\Navigation\Item; $navigation->addIf($isAdmin, 'Settings', function (Item $item) { // ... }); $navigation->addUnless($isReader, 'Articles', function (Item $item) { // ... });
部分
添加部分
use Felix\Navigation\Item; use Felix\Navigation\Section; $navigation->addSection('Name', function (Section $section) { $section->add('Child', function (Item $item) { // ... }); });
条件渲染部分
use Felix\Navigation\Section; $navigation->addSectionIf($isAdmin, 'Admin', function (Section $section) { // ... }); $navigation->addSectionUnless($isReader, 'Bookmarks', function (Section $section) { // ... });
项
/** @var \Felix\Navigation\Item $item **/ $item->route('articles.index'); $item->route('tenant.show', ['tenant' => 1]); $item->url('https://github.com/felixdorn') $item->route('articles.index') ->activeWhenRouteMatches('articles.*') // active for articles.index / articles.edit / articles.anything $item->meta(['a' => 'b']); // same as $item->a('b');
测试
composer test
为Laravel的导航 由 Félix Dorn 在 MIT许可 下创建。