1
I need to build a menu using the registered categories. How can I do this without using a view?
I have my layout.blade.php with a @include('sidebar')
My consultation works on view categorias.blade.php, I just need to receive the data of the query in my sidebar.blade.php
Categoriacontroller:
public function listar() {
$categorias = Categoria::where('categoria_id', '0')->with('todasCategorias')->get();
return view('categorias', compact('categorias'));
}
I made the direct consultation on sidebar.blade.php.
It worked, but I think this is not the right way, someone knows another way?
$categorias = App\Categoria::where('categoria_id', '0')->with('todasCategorias')->get()
Diego, thank you for the answer. I don’t think I was very clear. Actually this sidebar.blade.php is not in the category.blade.php. The sidebar will be on every page of the site. I import the sidebar in my layout.blade.php
– buback
Knows how to use the function
__construct?– Diego Souza
Yes, but it doesn’t work that way. Remembering that the
viewcategoriashas nothing to do with thesidebar. In fact where hascategoriasnor has thesidebar.– buback
The
sidebardoesn’t go on every page ? Just put this function__construct()in the controller main, which calls all its pages.– Diego Souza