stevebauman / active
一个用于输出当前路由类别的Active链接助手。
该包的规范仓库似乎已不存在,因此该包已被冻结。
    v2.0.0
    2021-01-05 22:38 UTC
Requires
- php: >=7.0
- illuminate/support: *
Requires (Dev)
This package is auto-updated.
Last update: 2024-04-06 06:00:14 UTC
README
一个Active HTML类助手,根据当前路由回显字符串。
🚨 被遗弃 🚨
为了Laravel现在默认实现,这个包已被遗弃。
request()->routeIs($pattern);
上述方法现在适用于版本5.4或更高版本的任何Laravel应用。
这个仓库仍然会在Packagist和GitHub上保持活跃。
安装
在您的composer.json中插入active
"stevebauman/active": "1.0.*"
在config/app.php中插入服务提供者,仅当您需要配置文件时才需要。
\Stevebauman\Active\ActiveServiceProvider::class,
运行composer update,您就设置好了!
用法
本文档将使用active()助手。
默认输出类为active,这是显示按钮和链接的标准bootstrap类,如果它们与当前URL匹配,则显示不同颜色。
在活动路由或路由上输出
<!-- `active` will be displayed when you visit `products/` --> <a class="btn btn-success {{ active()->route('products.index') }}" href="{{ route('products.index') }}"> Products </a>
<!-- `active` will be displayed when you visit `products/` or `products/create` --> <a class="btn btn-success {{ active()->routes(['products.index', 'products.create']) }}" href="{{ route('products.index') }}"> Products </a>
要输出任何特定路由下的活动,请在您的路由中使用通配符(*)。
例如
<!-- `active` will be displayed when you visit any route below `products.` --> <a class="btn btn-success {{ active()->route('products.*') }}" href="{{ route('products.index') }}"> Products </a>
<!-- `active` will be displayed when you visit any route below `products.`, or `suppliers.` --> <a class="btn btn-success {{ active()->routes(['products.*', 'suppliers.*']) }}" href="{{ route('products.index') }}"> Products </a>
设置不同的输出
要设置不同的输出,请使用output()方法
<a
    class="btn btn-success {{ active()->output('my-active-class')->route('products.*') }}"
    href="{{ route('products.index') }}">
        Products
</a>