I am trying to view dynamic menu into my application. I made my policy that I will have a table and I will add menu items by myself into the table. I have a table Menu_Panel like this:
id menu_name parent_menu_id
1 root 0
4 user 1
5 sales 1
6 user-list 2
For nested items I made a query and Then I executed the query which outputs are below:
Array
(
[1] => Array
(
[id] => 1
[menu_name] => root
[parent_menu_id] => 0
[sub-menu] => Array
(
[4] => Array
(
[id] => 4
[menu_name] => user
[parent_menu_id] => 1
[sub-menu] => Array
(
[6] => Array
(
[id] => 6
[menu_name] => user-list
[parent_menu_id] => 2
)
)
)
[5] => Array
(
[id] => 5
[menu_name] => Sales
[parent_menu_id] => 1
)
)
)
)
Now I think, I got my desired result cause it looks like nested. Now I want to show this recursive menu items in ul->li into my view page. Here is my code: I kept the result into $side_bar_menu::
@foreach($side_bar_menu as $module)
<li class="mm-dropdown">
<a href="#"><i class="menu-icon fa fa-columns"></i><span class="mm-text">User </span></a>
<ul>
@foreach($module['sub-menu'] as $sub_module)
<li>
<a tabindex="-1" href="{{route('menu-panel')}}"><span class="mm-text">Menu Panel</span></a>
</li>
@endforeach
</ul>
</li>
@endforeach
I think I miss something in foreach. in this case $module['sub-menu'] is not working. As I noticed that array indexing number are not sequential.
My question is that how may I view the item lists in my view file in php ?