/** * Build navigation tree structure. * * @param Menu $menu * @return mixed */ public function buildMenu(Menu $menu) { $items = Page::with('url')->where('menu', $menu->code)->orderBy('sort_order')->get()->groupBy('parent_id'); if (count($items)) { $items['root'] = $items['']; unset($items['']); } return $items; }
/** * Create page tree structure. * * @param string $code Menu type code * * @return \Illuminate\Database\Eloquent\Collection */ public static function buildTreeMenu($code) { $items = Page::with('url')->where('menu', $code)->get()->groupBy('parent_id'); if ($items->count()) { $items['root'] = $items['']; unset($items['']); } else { $items = collect(['root' => collect()]); } return $items; }