title: Getting array of objects in laravel blade
body: <p>Am developing a website like Olx.
  I want to append the main categories and sub categories in menu bar.
  Am getting the return object like this for each element:
  <a href="https://i.stack.imgur.com/fqnnv.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/fqnnv.png" alt="enter image description here"></a></p>
  
  <p>My controller code is:</p>
  
  <pre><code>$all_categories = [];
          $main_categories_name = Category::where('parent_id', 0)-&gt;pluck('name')-&gt;toArray();
          $main_categories_id = Category::where('parent_id', 0)-&gt;pluck('id')-&gt;toArray();        
          foreach($main_categories_id as $id){
            $name = Category::where('id', $id)-&gt;pluck('name');
            $sub_categories = Category::where('parent_id', $id)-&gt;pluck('name')-&gt;toArray();
            $all_categories[] = array('name' =&gt; $name, 'sub_categories' =&gt; $sub_categories);
          } 
          return $all_categories;
  </code></pre>
  
  <p>How do I get these elements in blade?</p>
  
  <pre><code>@foreach($all_categories as $category) 
                  @foreach($category['name'] as $category) 
                    &lt;li id="{{$category}}" name="{{$category}}" class="dropdown-submenu main_category"&gt; &lt;a class="maincategory" tabindex="-1" href="#"&gt;&lt;span class="categoryname"&gt;{{$category}}&lt;/span&gt;&lt;/a&gt;
                      &lt;ul class="dropdown-menu"&gt;
                        &lt;li class="subcategory" id="subcat"&gt; sub_category
                        &lt;/li&gt;
                      &lt;/ul&gt;
                    &lt;/li&gt;
                  @endforeach
              @endforeach
  </code></pre>
  
  <p>I used like this. Now I want sub_categories in the name where I mentioned sub_category.</p>
  
  <p>Am getting like this:
  <a href="https://i.stack.imgur.com/OWjSX.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/OWjSX.png" alt="enter image description here"></a></p>
  
  <p>After using this code:</p>
  
  <pre><code>&lt;ul class="dropdown-menu multi-level"&gt;
              @foreach($all_categories as $category)                 
                &lt;li id="{{$category['name']}}" name="{{$category['name']}}" class="dropdown-submenu main_category"&gt; &lt;a class="maincategory" tabindex="-1" href="#"&gt;&lt;span class="categoryname"&gt;{{$category['name']}}&lt;/span&gt;&lt;/a&gt;
                  &lt;ul class="dropdown-menu"&gt;
                  @foreach($category['sub_categories'] as $category) 
                    &lt;li class="subcategory" id="subcat"&gt;&lt;a href="#"&gt;{{$category}}&lt;/a&gt;&lt;/li&gt;
                  @endforeach
                  &lt;/ul&gt;
                &lt;/li&gt;
              @endforeach
              &lt;/ul&gt;
  </code></pre>
  
  <p>What to do for this? Am getting empty array like this?
  <a href="https://i.stack.imgur.com/6CeTE.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6CeTE.png" alt="enter image description here"></a></p>