/** * Display the specified resource. * * @param int $id * @return Response */ public function show($id) { // Make sure resource exists $this->resource = $this->resource->findOrFail($id); $this->subtitle = $this->resource; return parent::show($id); }
/** * Display the subtree of a category. * * @param int $id * @return Response */ public function show($id) { // Make sure resource exists $this->resource = $this->resource->findOrFail($id); $this->subtitle = $this->resource; // Get subcategories $subcategories = $this->resource->getDescendants(); // Get pages this category $pages = $this->resource->pages()->orderBy('name')->get(); // Get pages of subcategories $subpages = Page::whereIn('category_id', $subcategories->lists('id'))->orderBy('name')->get(); // Function to render a tree node $render = function (array $node) { return link_to_route('category.show', $node['name'], [$node['id']]); }; // Build subcategories tree $tree = tree($subcategories->toHierarchy()->toArray(), $render); view()->share(compact('pages', 'subpages', 'subcategories', 'tree')); return parent::show($id); }