To check for user permissions on nested menu items, you can apply the same logic you used for the top-level menu items. You need to add a conditional check within your @for loops to determine if the user has the required permissions for each nested menu item. Here's how you can modify your nested @for loops:
@foreach ($decodedMenu->menuList as $key => $value)
{{-- Check if the menu item has permissions set and if the user has any of the required roles --}}
@if (!isset($value->permissions) || auth()->user()->hasAnyRole($value->permissions))
{{-- ... existing code for top-level menu items ... --}}
@if (isset($value->child))
{{-- Parent menu item code here --}}
<ul>
{{-- Begin For Loop for child items --}}
@foreach ($value->child as $child)
{{-- Check permissions for child menu item --}}
@if (!isset($child->permissions) || auth()->user()->hasAnyRole($child->permissions))
<li>
{{-- Child menu item code here --}}
<a href="{{ $child->link }}">
{{-- ... --}}
</a>
{{-- Check for subChild items --}}
@if (isset($child->subChild))
<ul>
{{-- Begin For Loop for subChild items --}}
@foreach ($child->subChild as $subChild)
{{-- Check permissions for subChild menu item --}}
@if (!isset($subChild->permissions) || auth()->user()->hasAnyRole($subChild->permissions))
<li>
{{-- SubChild menu item code here --}}
<a href="{{ $subChild->link }}">
{{-- ... --}}
</a>
</li>
@endif
@endforeach
{{-- End For Loop for subChild items --}}
</ul>
@endif
</li>
@endif
@endforeach
{{-- End For Loop for child items --}}
</ul>
@endif
@endif
@endforeach
In this solution, I replaced the @for loops with @foreach loops for better readability and to avoid manual index management. Each nested loop checks if the permissions property is set for the child or subChild item and if the user has any of the required roles using auth()->user()->hasAnyRole($child->permissions) or auth()->user()->hasAnyRole($subChild->permissions) respectively.
This way, you ensure that each menu item, whether it's a top-level, child, or subChild item, is only displayed if the user has the appropriate permissions.