There is not enough context in your question to be sure what you are trying to achieve, but I assume you just want subOne to be true when there is a Sub Menu 1, and subTwo to be true when Sub Menu 2 exists.
If you are generating the menu from the backend, why not do something like
<nav class="{{ $menuItem->getSubMenu() ? 'has-sub-menu-1' : '' }}{{ $menuItem->getSubMenu()?->getSubMenu() ? ' has-sub-menu-2' : '' }}">
<ul>
<li>{{ $menuItem->name }}</li>
@if ($subMenuItem = $menuItem->getSubMenu())
<ul>
<li>{{ $subMenuItem->name }}
@if ($subMenuItemTwo = $subMenuItem->getSubMenu())
<ul>
<li>{{ $subMenuItemTwo->name }}</li>
</ul>
@endif
</li>
</ul>
@endif
</nav>
If you are using AlpineJS to actually build the menu from some data source, please include the complete code. In this case, you can build the condition for :class
from the data structure you have.
It's actually very hard to give you any suggestions without knowing how the menu is generated, but the pseudoish code above should give you an idea of what your options are.
(Please note that above code uses PHP 8 syntax, if you use Laravel you can use optional($menuItem->getSubMenu())->getSubMenu()
instead).
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…