[扩展] hieu-le active 判断导航元素的 active 状态
说明
hieu-le/active扩展可以用来为Laravel提供导航元素的 active 状态,比如菜单导航的选中等。
使用 Composer 安装 hieu-le/active
composer require "hieu-le/active:~3.5"
如果在Laravel5.5以下版本,还需要手动添加:
修改 config/app 文件,添加 ServiceProvider:
在 providers 数组内追加如下内容
'providers' => [
...
HieuLe\Active\ActiveServiceProvider::class,
],
在 aliases 数组内追加如下内容
'aliases' => [
...
'Active' => HieuLe\Active\Facades\Active::class,
],
active_class用法
函数定义如下:
/**
* Get the active class if the condition is not falsy
*
* @param $condition
* @param string $activeClass
* @param string $inactiveClass
*
* @return string
*/
function active_class($condition, $activeClass = 'active', $inactiveClass = '')
函数说明:如果满足条件($condition),则函数返回 $activeClass ,否则返回 $inactiveClass
此外,这个扩展还包含了一些函数提供调用
if_route() - 判断当前对应的路由是否是指定的路由;
if_route_param() - 判断当前的 url 有无指定的路由参数。
if_query() - 判断指定的 GET 变量是否符合设置的值;
if_uri() - 判断当前的 url 是否满足指定的 url;
if_route_pattern() - 判断当前的路由是否包含指定的字符;
if_uri_pattern() - 判断当前的 url 是否含有指定的字符;
本作品采用《CC 协议》,转载必须注明作者和本文链接
推荐文章: