Laravel 5.1 高亮菜单

最近基于Laravel5.1做项目开发,后台菜单高亮,原来用jQuery做菜单高亮,但发现到了新方法里就不奏效了,还是在定义变量在View层判断即可。

基类

定义两个变量,并共享到所有模板里

class BaseController extends Controller
{
    public $module;
    public $parent_module;
    public function __construct()
    {
        View::share('active',[$this->module=>'active']);
        View::share('parent_active',[$this->parent_module=>'active']);

    }
}

继承的类
(赋值变量)

class ShopCategoryTagController extends BaseController
{

    public $module = 'cate_tag';
    public $parent_module = 'parent_shop';

视图层

父级

<li class="treeview {{isset($parent_active['parent_shop']) ? $parent_active['parent_shop'] : ''}}">

子级

<li class="{{isset($active['cate_tag']) ? $active['cate_tag'] : ''}}"><a href="{{url('admin/shop_category_tag')}}">

效果:

《Laravel 5.1 高亮菜单》

原文地址:http://note.mango.im/article/6

    原文作者:mangostudio
    原文地址: https://segmentfault.com/a/1190000003809174
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞