Laravel is a PHP framework, which offers clean solution to build your website, especially data driven ones(i.e. not static pages, rather the content is retrieved from a back-end database like MySQL)  . I’m not going to discuss much about Laravel’s terms, such as view, controller, routes here since this posts only focuses on a “dynamic menu”. You can find more Laravel information here.


Below is the code from “layouts” view(bootstrapped), which is used as a template for all other pages.

The basic menu items are “FrontPage” and “About-us” and we use @yield(‘dynamicGroup’) as a place holder to indicate that other dynamic menu items will be placed here.

<div class=”navbar navbar-inverse navbar-fixed-top” role=”navigation”>
<div class=”container”>
<div class=”navbar-header”>
<button type=”button” class=”navbar-toggle” data-toggle=”collapse” data-target=”.navbar-collapse”>
<span class=”icon-bar”></span>
<span class=”icon-bar”></span>
<span class=”icon-bar”></span>
<a class=”navbar-brand” href=”/”>SomethingSomething</a>
<div class=”navbar-collapse collapse”>
<ul class=”nav navbar-nav”>
<li><a href=”/showcars”><b>Our Cars</b></a></li>
<li><a href=”/”><span class=”glyphicon glyphicon-home”></span>FrontPage</a></li>
<!– dymanic menu,ensure it’s not too many! –>
<li><a href=”/about-us”>About-us</a></li>
<!– <li><a href=”#contact”>contact us</a></li> –>
</div><!–/.navbar-collapse –>


On each page(i.e view) you simply need to insert the following code to build menu items on-the-fly. In my below example $tourgroups contains a list of items that I want to show on the menu.

@foreach($tourgroups as $tourgrp)
<li><a href=”/tourgroup/{{ $tourgrp->id }}” class=”route”>{{$tourgrp->name}}</a></li>

Of course, before the view is called, you’ll need to populate $tourgroups and pass to the view like below:

return View::make(‘home.index’)




Making dynamic menus using Laravel
Tagged on:                     

5 thoughts on “Making dynamic menus using Laravel

  • May 10, 2014 at 11:14 pm

    great article, very clear and helps me a lot, thanks!

  • July 1, 2014 at 10:42 pm

    I have to tell you that it’s hard to find your articles in google,
    i found this one on 18 spot, you should build some quality backlinks in order to rank your webiste, i
    know how to help you, just type in google – k2 seo tips and tricks

  • July 6, 2014 at 8:04 pm

    I see a lot of interesting articles on your blog.
    You have to spend a lot of time writing, i know how to save you a lot of work, there is a tool that creates unique, SEO friendly
    articles in couple of minutes, just type in google – laranita’s
    free content source

  • July 13, 2014 at 7:44 pm

    Really no matter if someone doesn’t know after that its
    up to other viewers that they will assist, so here it occurs.

  • September 1, 2014 at 1:10 pm

    I read a lot of interesting posts here. Probably you spend a lot of time writing, i know how to save you
    a lot of time, there is an online tool that creates readable, SEO friendly articles in minutes, just search in google
    – laranitas free content source


Leave a Reply

Your email address will not be published.

1 + 5 =

This site uses Akismet to reduce spam. Learn how your comment data is processed.