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

pcbimon's avatar

How to Add Custom menu in Voyager Laravel?

I'm newbie for laravel. I can create list of menu but I can't route to it. I read document in How to Create Custom Menu. I confuse this code.

Menu::display('main', 'bootstrap');

And

<ul>
    @foreach($items as $menu_item)
        <li><a href="{{ $menu_item->url }}">{{ $menu_item->title }}</a></li>
    @endforeach
</ul>

And

Menu::display('main', 'my_menu');

I don't know this code need to put it somewhere. Doc Ref

0 likes
3 replies
abhinandan's avatar

Hi the following code is for custom coding on front end

Custom Query in Controller :

use DB; public function index(){

    $menu = DB::select('select * from menu_items where menu_id=2');

    return view('index',['menu' => $menu]);

}

index.blade.php

    @foreach($items as $menu_item)
    
        <li><a href="{{ $menu_item->url }}">{{ $menu_item->title }}</a></li>
    
    @endforeach
    
Ty's avatar

The first code is if you just want to use the menu using their default styling with bootstrap.

Menu::display('main', 'bootstrap');

The following code block allows you to add custom styling to your menu out of the box. If you wish to use this code block you would place this

<ul>
    @foreach($items as $menu_item)
        <li><a href="{{ $menu_item->url }}">{{ $menu_item->title }}</a></li>
    @endforeach
</ul>

in a blade file resources/views/my_menu.blade.php. then you would display it in your view file where you want it to display. using Menu::display('main', 'my_menu');

Please or to participate in this conversation.