承接 tuytoosh/active 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

tuytoosh/active

最新稳定版本:1.8.2

Composer 安装命令:

composer require tuytoosh/active

包简介

Active class in blade templates

README 文档

README

Installation

For installation use this command:

composer require tuytoosh/active

Publish configuration

A simple configuration file has a config key for default active class. Use

php artisan vendor:publish --tag=config --force

in order to publish the configuration file. The config key is located in ./config/active.php file and you can replace the default value with your own. In the configuration you can change default active and inactive classes. For example you can use tailwind classes to activate or deactivate navbar menu items:

<?php

return [
    'class' => 'active',
    'inactive_class' => '',
];

How to use

With this package instead of using:

class="@if(Route::currentRouteName() == 'home') active @endif"

In blade files you can simply use:

class="@active('home')"

Override default active and inactive classes

You can override the default active class by passing second parameter to the directive like this:

class="@active('home', 'open', 'closed')"

Use * for all routes

  • class="@active('*')" will be active for all routes
  • class="@active('admin.*')" will be active for all routes that starts with admin.
  • class="@active('admin.post.*', 'open')" will be open for all routes that starts with admin.post.

Array of routes

You can pass an array of routes as first parameter to the directive like this:

class="@active(['admin.dashboard', 'user.dashboard'])"

* and exact patterns will work as well.

active() and isActive() helpers

All features are available in active() helper function. for example you can use it in your controller like this:

// returns string
$class = active('home');

or

// returns boolean
if(isActive('home')){

}

Todo

  • Add support for * at the end of route name
  • Add tests
  • Make it compatible with older versions of Laravel
  • Support for route parameters!
  • support for array of route patterns

License

MIT

Contributing

Please feel free to fork this project and make pull requests. Test env is ready to use with orchestra testbench and you just need run:

composer install
./vendor/bin/phpunit --debug --colors

统计信息

  • 总下载量: 1.15k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 14
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 14
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-05-05