分类激活判断的一些帮助函数
公司里没办法用 composer, 就发到这里留个笔记
function active_class($condition, $activeClass = 'active', $inactiveClass = ''){
return $condition ? $activeClass : $inactiveClass;
}
function if_route($routeName){
$routeNames = Route::currentRouteName();
return in_array($routeName, (array)$routeNames);
}
function if_route_param($param, $value) {
$paramValue = Route::input($param);
if (is_a($paramValue, Model::class)) {
return $paramValue->{$paramValue->getKeyName()} == $value;
}
return $paramValue == $value;
}
function category_nav_active($category_id){
return active_class((if_route('categories.show') && if_route_param('category', $category_id)));
}
推荐文章: