msurguy / laravel-shop-menu

Menu ordering/management application demo, like Wordpress menu manager
http://laravel-menu-builder.gopagoda.com/admin/menu
334 stars 100 forks source link

Rendering issue #7

Closed robertnicjoo closed 5 years ago

robertnicjoo commented 5 years ago

This is what I get in return

121

code

model

public function buildMenu($menu, $parentid = 0) 
    { 
      $result = null;
      foreach($menu as $item) 
        if ($item->parent_id == $parentid) { 
          $result .= "<li class='dd-item nested-list-item' data-order='{$item->order}' data-id='{$item->id}'>
          <div class='dd-handle nested-list-handle'>
            <i class='fas fa-arrows-alt'></i>
          </div>
          <div class='nested-list-content'>{$item->title}
            <div class='float-right'>
              <a href='/admin/menusnav/{$item->id}'>Edit</a> |
              <a href='#' class='delete_toggle text-danger' rel='{$item->id}'>Delete</a>
            </div>
          </div>".$this->buildMenu($menu, $item->id) . "</li>"; 
        } 
      return $result ?  "\n<ol class=\"dd-list\">\n$result</ol>\n" : null; 
    }
    // Getter for the HTML menu builder
    public function getHTML($items)
    {
        return $this->buildMenu($items);
  }

controller

public function index() {
                 $categories = Category::orderby('title', 'asc')->get();
        //navbar
        $navbars = NavbarMenu::orderby('order', 'asc')->get();

        $navbar = new NavbarMenu;
               $navbar = $navbar->getHTML($navbars);

        return view('admin.menus.index', compact('navbars', 'navbar'));
    }

and my blade

{!! $navbar !!}

Any idea what might cause the problem?

robertnicjoo commented 5 years ago

Anyone?

msurguy commented 5 years ago

@robertnicjoo it seems like you're getting navbars rendered instead of navbar... can you dd($navbar); before you do a return statement and tell me what the output is?

robertnicjoo commented 5 years ago

@msurguy thanks for respond here is my dump result

Using blade dd {{dd($navbar)}}

Collection {#1825 ▼
  #items: array:2 [▼
    0 => NavbarMenu {#1771 ▼
      #fillable: array:5 [▶]
      #connection: "mysql"
      #table: "navbar_menus"
      #primaryKey: "id"
      #keyType: "int"
      +incrementing: true
      #with: []
      #withCount: []
      #perPage: 15
      +exists: true
      +wasRecentlyCreated: false
      #attributes: array:8 [▶]
      #original: array:8 [▼
        "id" => 2
        "title" => "Who We Are"
        "slug" => "#"
        "category_id" => null
        "parent_id" => null
        "order" => 2
        "created_at" => "2018-10-23 11:58:12"
        "updated_at" => "2018-10-23 11:58:12"
      ]
      #changes: []
      #casts: []
      #dates: []
      #dateFormat: null
      #appends: []
      #dispatchesEvents: []
      #observables: []
      #relations: array:1 [▼
        "children" => Collection {#1790 ▼
          #items: []
        }
      ]
      #touches: []
      +timestamps: true
      #hidden: []
      #visible: []
      #guarded: array:1 [▶]
    }
    1 => NavbarMenu {#1772 ▼
      #fillable: array:5 [▶]
      #connection: "mysql"
      #table: "navbar_menus"
      #primaryKey: "id"
      #keyType: "int"
      +incrementing: true
      #with: []
      #withCount: []
      #perPage: 15
      +exists: true
      +wasRecentlyCreated: false
      #attributes: array:8 [▼
        "id" => 5
        "title" => "Deeps (L.1)"
        "slug" => null
        "category_id" => null
        "parent_id" => null
        "order" => 5
        "created_at" => "2018-10-23 12:01:32"
        "updated_at" => "2018-10-23 12:01:32"
      ]
      #original: array:8 [▶]
      #changes: []
      #casts: []
      #dates: []
      #dateFormat: null
      #appends: []
      #dispatchesEvents: []
      #observables: []
      #relations: array:1 [▼
        "children" => Collection {#1824 ▼
          #items: array:1 [▼
            0 => NavbarMenu {#1819 ▼
              #fillable: array:5 [▶]
              #connection: "mysql"
              #table: "navbar_menus"
              #primaryKey: "id"
              #keyType: "int"
              +incrementing: true
              #with: []
              #withCount: []
              #perPage: 15
              +exists: true
              +wasRecentlyCreated: false
              #attributes: array:8 [▶]
              #original: array:8 [▼
                "id" => 6
                "title" => "Deeps (L.2)"
                "slug" => "#"
                "category_id" => null
                "parent_id" => 5
                "order" => 6
                "created_at" => "2018-10-23 12:01:49"
                "updated_at" => "2018-10-23 12:01:49"
              ]
              #changes: []
              #casts: []
              #dates: []
              #dateFormat: null
              #appends: []
              #dispatchesEvents: []
              #observables: []
              #relations: []
              #touches: []
              +timestamps: true
              #hidden: []
              #visible: []
              #guarded: array:1 [▶]
            }
          ]
        }
      ]
      #touches: []
      +timestamps: true
      #hidden: []
      #visible: []
      #guarded: array:1 [▶]
    }
  ]
}

Using controller dd dd($navbar);

"""
\n
<ol class="dd-list">\n
<li class='dd-item nested-list-item' data-order='2' data-id='2'>\n
\t      <div class='dd-handle nested-list-handle'>\n
            <i class='fas fa-arrows-alt'></i>\n
\t      </div>\n
\t      <div class='nested-list-content'>Who We Are\n
\t        <div class='float-right'>\n
\t          <a href='/admin/menusnav/2'>Edit</a> |\n
\t          <a href='#' class='delete_toggle text-danger' rel='2'>Delete</a>\n
\t        </div>\n
\t      </div></li><li class='dd-item nested-list-item' data-order='5' data-id='5'>\n
\t      <div class='dd-handle nested-list-handle'>\n
            <i class='fas fa-arrows-alt'></i>\n
\t      </div>\n
\t      <div class='nested-list-content'>Deeps (L.1)\n
\t        <div class='float-right'>\n
\t          <a href='/admin/menusnav/5'>Edit</a> |\n
\t          <a href='#' class='delete_toggle text-danger' rel='5'>Delete</a>\n
\t        </div>\n
\t      </div>\n
<ol class="dd-list">\n
<li class='dd-item nested-list-item' data-order='6' data-id='6'>\n
\t      <div class='dd-handle nested-list-handle'>\n
            <i class='fas fa-arrows-alt'></i>\n
\t      </div>\n
\t      <div class='nested-list-content'>Deeps (L.2)\n
\t        <div class='float-right'>\n
\t          <a href='/admin/menusnav/6'>Edit</a> |\n
\t          <a href='#' class='delete_toggle text-danger' rel='6'>Delete</a>\n
\t        </div>\n
\t      </div>\n
<ol class="dd-list">\n
<li class='dd-item nested-list-item' data-order='7' data-id='7'>\n
\t      <div class='dd-handle nested-list-handle'>\n
            <i class='fas fa-arrows-alt'></i>\n
\t      </div>\n
\t      <div class='nested-list-content'>Deeps (L.3)\n
\t        <div class='float-right'>\n
\t          <a href='/admin/menusnav/7'>Edit</a> |\n
\t          <a href='#' class='delete_toggle text-danger' rel='7'>Delete</a>\n
\t        </div>\n
\t      </div></li></ol>\n
</li></ol>\n
</li></ol>\n
"""
robertnicjoo commented 5 years ago

@msurguy no? nothing?

robertnicjoo commented 5 years ago

@msurguy no? nothing?

still waiting :/