juanintorres / menu-elements
菜单元素生成器,这是作为一个练习开发的,因此并不是一个非常完善的开发
v1.0
2017-08-17 12:51 UTC
Requires
- php: >=7.0
- illuminate/support: ^5.4.27
Requires (Dev)
- phpunit/phpunit: ^5.7.21
- symfony/var-dumper: ^3.3.6
This package is not auto-updated.
Last update: 2024-09-29 03:36:28 UTC
README
这个组件帮助我们创建菜单元素,如果链接指向的路由与当前路径相同,则会添加一个额外的CSS类。
这是作为一个练习创建的,因此是公共用途的,欢迎接受所有类型的意见和评论。
图标使用的基类是 glyphicon
,这是 Bootstrap 使用的,但可以在生成本地配置文件时更改。
安装
步骤 1:通过 composer 安装
composer require "juanintorres/menuelement":"dev-master"
步骤 2:添加 ServiceProvider 和 Facade
在文件 config/app.php
中添加
... 'providers' => [ Juanintorres\MenuElement\MenuElementServiceProvider::class, ], ... 'aliases' => [ 'MenuElement' => Juanintorres\MenuElement\MenuElement::class, ]
步骤 3:生成本地配置文件
php artisan vendor:publish --force
执行此操作时,将从包中复制一个配置文件到 /config/menuelement.php
路径。
示例
在一个视图或部分中,如果有导航菜单,请使用以下代码
<ul> {!! MenuElement::make('home_path','HOME', ['icon' => 'glyphicon glyphicon-home']) !!} {!! MenuElement::make('contact_path','Contacto', ['icon' => 'glyphicon glyphicon-envelope']) !!} </ul>
如果我们已经定义了这些路由
Route::get('home', [ 'as' => 'home_path', 'uses' => 'HomeController@index' ]); Route::get('contacto', [ 'as' => 'contact_path', 'uses' => 'ContactController@index' ]);
如果我们位于 home
,这将产生以下结果
<ul> <li class="active"><a href="http://app.dev"><span class="glyphicon glyphicon-home" aria-hidden="true"></span>HOME</a></li> <li class=""><a href="http://app.dev/contacto"><span class="glyphicon glyphicon-envelope" aria-hidden="true"></span>Contacto</a></li> </ul>