Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

codemaster96's avatar

How to display dynamic navigation bar from blade template

I have a navigation bar stored in the database, and I have a Controller witch lists the navbar for my template file.

$navbar=/*Query*/
return view('inc.template')->with('nav',$navbar);

I have other pages where I want to use the template with the navigation bar of course, but when I extend the template I get error message 'Undefined variable $nav'. I understand why I get this error message, because I don't returned the variable for the other page. So I need solution for this.. every idea is welcome!.

I have single product page, where I want to include the template with the navigation bar and also I will list the Single Product here.

I know I can copy the query code and paste it to the single product controller, but I believe this is not a good solution (repeating myself).

Thanks in advance for your ideas!

0 likes
3 replies
MarianoMoreyra's avatar

You’re welcome @codemaster96

If this actually works for you, please remember to mark the question as replied so others can found this solution easier on the future

Please or to participate in this conversation.