alpine js open sidebar one at time
@php
$menus = [
'users.*' => 'users',
'roles.*' => 'roles',
];
$selectedMenu = \Illuminate\Support\Arr::first($menus, fn($menu, $key) => request()->routeIs($key));
@endphp
<ul class="navbar-nav flex-column" x-data="{ selected: '{{$selectedMenu}}' }">
<li class="nav-item" @click="selected = 'users'">
<a class="nav-link collapsed" :class="{ 'top-active': selected === 'users' }"
href="#" data-toggle="collapse"
x-bind:aria-expanded="{ 'true': selected === 'users' }"
data-target="#submenu-users" aria-controls="submenu-users"
>
<i class="fas fa-fw fa-users"></i>Users
</a>
<div id="submenu-users" class="submenu collapse" :class="{ 'show': selected === 'users' }">
<ul class="nav flex-column">
<li class="nav-item">
<a class="nav-link {{ request()->routeIs('users.index') ? 'active' : '' }}" href="{{ route('users.index') }}">All Users</a>
</li>
</ul>
</div>
</li>
</ul>