我想避免 @elseif 語句應(yīng)用正則表達(dá)式。嘗試了一些方法但沒有任何運(yùn)氣。@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貢獻(xiàn)1773條經(jīng)驗(yàn) 獲得超3個(gè)贊
您可以將多個(gè)模式傳遞給is:
request()->is('*backend/categories*', '*backend/products*', ...)
也許您需要一個(gè)輔助函數(shù)來從視圖中刪除邏輯:
function isActive($patterns, $class = 'active')
{
return request()->is($patterns) ? $class : '';
}
class="... {{ isActive(['*backend/categories*', '*backend/products*']) }}"
- 1 回答
- 0 關(guān)注
- 137 瀏覽
添加回答
舉報(bào)
0/150
提交
取消