我想避免 @elseif 语句应用正则表达式。尝试了一些方法但没有任何运气。@if(request()->is('*backend/categories*')) active @elseif(request()->is('*backend/products*')) active @endif更新:<a href="#" class="nav-link @if(request()->is('*backend/categories*')) active @elseif(request()->is('*backend/products*')) active @endif">
1 回答
慕容3067478
TA贡献1773条经验 获得超3个赞
您可以将多个模式传递给is:
request()->is('*backend/categories*', '*backend/products*', ...)
也许您需要一个辅助函数来从视图中删除逻辑:
function isActive($patterns, $class = 'active')
{
return request()->is($patterns) ? $class : '';
}
class="... {{ isActive(['*backend/categories*', '*backend/products*']) }}"
- 1 回答
- 0 关注
- 96 浏览
添加回答
举报
0/150
提交
取消